本文整理汇总了TypeScript中vs/editor/common/model.ITextModel.getValueInRange方法的典型用法代码示例。如果您正苦于以下问题:TypeScript ITextModel.getValueInRange方法的具体用法?TypeScript ITextModel.getValueInRange怎么用?TypeScript ITextModel.getValueInRange使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类vs/editor/common/model.ITextModel
的用法示例。
在下文中一共展示了ITextModel.getValueInRange方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: resolve
resolve(variable: Variable): string {
const { name } = variable;
if (name === 'SELECTION' || name === 'TM_SELECTED_TEXT') {
let value = this._model.getValueInRange(this._selection) || undefined;
if (value && this._selection.startLineNumber !== this._selection.endLineNumber) {
// Selection is a multiline string which we indentation we now
// need to adjust. We compare the indentation of this variable
// with the indentation at the editor position and add potential
// extra indentation to the value
const line = this._model.getLineContent(this._selection.startLineNumber);
const lineLeadingWhitespace = getLeadingWhitespace(line, 0, this._selection.startColumn - 1);
let varLeadingWhitespace = lineLeadingWhitespace;
variable.snippet.walk(marker => {
if (marker === variable) {
return false;
}
if (marker instanceof Text) {
varLeadingWhitespace = getLeadingWhitespace(marker.value.split(/\r\n|\r|\n/).pop());
}
return true;
});
const whitespaceCommonLength = commonPrefixLength(varLeadingWhitespace, lineLeadingWhitespace);
value = value.replace(
/(\r\n|\r|\n)(.*)/g,
(m, newline, rest) => `${newline}${varLeadingWhitespace.substr(whitespaceCommonLength)}${rest}`
);
}
return value;
} else if (name === 'TM_CURRENT_LINE') {
return this._model.getLineContent(this._selection.positionLineNumber);
} else if (name === 'TM_CURRENT_WORD') {
const info = this._model.getWordAtPosition({
lineNumber: this._selection.positionLineNumber,
column: this._selection.positionColumn
});
return info && info.word || undefined;
} else if (name === 'TM_LINE_INDEX') {
return String(this._selection.positionLineNumber - 1);
} else if (name === 'TM_LINE_NUMBER') {
return String(this._selection.positionLineNumber);
}
return undefined;
}
示例2: _isSurroundSelectionType
private static _isSurroundSelectionType(config: CursorConfiguration, model: ITextModel, selections: Selection[], ch: string): boolean {
if (!TypeOperations._shouldSurroundChar(config, ch) || !config.surroundingPairs.hasOwnProperty(ch)) {
return false;
}
const isTypingAQuoteCharacter = isQuote(ch);
for (let i = 0, len = selections.length; i < len; i++) {
const selection = selections[i];
if (selection.isEmpty()) {
return false;
}
let selectionContainsOnlyWhitespace = true;
for (let lineNumber = selection.startLineNumber; lineNumber <= selection.endLineNumber; lineNumber++) {
const lineText = model.getLineContent(lineNumber);
const startIndex = (lineNumber === selection.startLineNumber ? selection.startColumn - 1 : 0);
const endIndex = (lineNumber === selection.endLineNumber ? selection.endColumn - 1 : lineText.length);
const selectedText = lineText.substring(startIndex, endIndex);
if (/[^ \t]/.test(selectedText)) {
// this selected text contains something other than whitespace
selectionContainsOnlyWhitespace = false;
break;
}
}
if (selectionContainsOnlyWhitespace) {
return false;
}
if (isTypingAQuoteCharacter && selection.startLineNumber === selection.endLineNumber && selection.startColumn + 1 === selection.endColumn) {
const selectionText = model.getValueInRange(selection);
if (isQuote(selectionText)) {
// Typing a quote character on top of another quote character
// => disable surround selection type
return false;
}
}
}
return true;
}
示例3: _trimEdit
static _trimEdit(editRange: Range, editText: string, editForceMoveMarkers: boolean, model: ITextModel): ISingleEditOperation {
let currentText = model.getValueInRange(editRange);
// Find the equal characters in the front
let commonPrefixLength = strings.commonPrefixLength(editText, currentText);
// If the two strings are identical, return no edit (no-op)
if (commonPrefixLength === currentText.length && commonPrefixLength === editText.length) {
return null;
}
if (commonPrefixLength > 0) {
// Apply front trimming
let newStartPosition = model.modifyPosition(editRange.getStartPosition(), commonPrefixLength);
editRange = new Range(newStartPosition.lineNumber, newStartPosition.column, editRange.endLineNumber, editRange.endColumn);
editText = editText.substring(commonPrefixLength);
currentText = currentText.substr(commonPrefixLength);
}
// Find the equal characters in the rear
let commonSuffixLength = strings.commonSuffixLength(editText, currentText);
if (commonSuffixLength > 0) {
// Apply rear trimming
let newEndPosition = model.modifyPosition(editRange.getEndPosition(), -commonSuffixLength);
editRange = new Range(editRange.startLineNumber, editRange.startColumn, newEndPosition.lineNumber, newEndPosition.column);
editText = editText.substring(0, editText.length - commonSuffixLength);
currentText = currentText.substring(0, currentText.length - commonSuffixLength);
}
return {
text: editText,
range: editRange,
forceMoveMarkers: editForceMoveMarkers
};
}
示例4: getEditOperations
public getEditOperations(model: ITextModel, builder: editorCommon.IEditOperationBuilder): void {
let text = model.getValueInRange(this.selection);
if (!this.copy) {
builder.addEditOperation(this.selection, null);
}
builder.addEditOperation(new Range(this.targetPosition.lineNumber, this.targetPosition.column, this.targetPosition.lineNumber, this.targetPosition.column), text);
if (this.selection.containsPosition(this.targetPosition) && !(
this.copy && (
this.selection.getEndPosition().equals(this.targetPosition) || this.selection.getStartPosition().equals(this.targetPosition)
) // we allow users to paste content beside the selection
)) {
this.targetSelection = this.selection;
return;
}
if (this.copy) {
this.targetSelection = new Selection(
this.targetPosition.lineNumber,
this.targetPosition.column,
this.selection.endLineNumber - this.selection.startLineNumber + this.targetPosition.lineNumber,
this.selection.startLineNumber === this.selection.endLineNumber ?
this.targetPosition.column + this.selection.endColumn - this.selection.startColumn :
this.selection.endColumn
);
return;
}
if (this.targetPosition.lineNumber > this.selection.endLineNumber) {
// Drag the selection downwards
this.targetSelection = new Selection(
this.targetPosition.lineNumber - this.selection.endLineNumber + this.selection.startLineNumber,
this.targetPosition.column,
this.targetPosition.lineNumber,
this.selection.startLineNumber === this.selection.endLineNumber ?
this.targetPosition.column + this.selection.endColumn - this.selection.startColumn :
this.selection.endColumn
);
return;
}
if (this.targetPosition.lineNumber < this.selection.endLineNumber) {
// Drag the selection upwards
this.targetSelection = new Selection(
this.targetPosition.lineNumber,
this.targetPosition.column,
this.targetPosition.lineNumber + this.selection.endLineNumber - this.selection.startLineNumber,
this.selection.startLineNumber === this.selection.endLineNumber ?
this.targetPosition.column + this.selection.endColumn - this.selection.startColumn :
this.selection.endColumn
);
return;
}
// The target position is at the same line as the selection's end position.
if (this.selection.endColumn <= this.targetPosition.column) {
// The target position is after the selection's end position
this.targetSelection = new Selection(
this.targetPosition.lineNumber - this.selection.endLineNumber + this.selection.startLineNumber,
this.selection.startLineNumber === this.selection.endLineNumber ?
this.targetPosition.column - this.selection.endColumn + this.selection.startColumn :
this.targetPosition.column - this.selection.endColumn + this.selection.startColumn,
this.targetPosition.lineNumber,
this.selection.startLineNumber === this.selection.endLineNumber ?
this.targetPosition.column :
this.selection.endColumn
);
} else {
// The target position is before the selection's end postion. Since the selection doesn't contain the target position, the selection is one-line and target position is before this selection.
this.targetSelection = new Selection(
this.targetPosition.lineNumber - this.selection.endLineNumber + this.selection.startLineNumber,
this.targetPosition.column,
this.targetPosition.lineNumber,
this.targetPosition.column + this.selection.endColumn - this.selection.startColumn
);
}
}