本文整理匯總了TypeScript中vscode.Position.isEqual方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Position.isEqual方法的具體用法?TypeScript Position.isEqual怎麽用?TypeScript Position.isEqual使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類vscode.Position
的用法示例。
在下文中一共展示了Position.isEqual方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: provideEdits
provideEdits(document: TextDocument, position: Position, ch: string, options: FormattingOptions, line: TextLine): TextEdit[] {
// We can have else for the following blocks:
// if:
// elif x:
// for x in y:
// while x:
// We need to find a block statement that is less than or equal to this statement block (but not greater)
for (let lineNumber = position.line - 1; lineNumber >= 0; lineNumber--) {
const prevLine = document.lineAt(lineNumber);
const prevLineText = prevLine.text;
// Oops, we've reached a boundary (like the function or class definition)
// Get out of here
if (this.boundaryRegExps.some(value => value.test(prevLineText))) {
return [];
}
const blockRegEx = this.previousBlockRegExps.find(value => value.test(prevLineText));
if (!blockRegEx) {
continue;
}
const startOfBlockInLine = prevLine.firstNonWhitespaceCharacterIndex;
if (startOfBlockInLine > line.firstNonWhitespaceCharacterIndex) {
continue;
}
const startPosition = new Position(position.line, 0);
const endPosition = new Position(position.line, line.firstNonWhitespaceCharacterIndex - startOfBlockInLine);
if (startPosition.isEqual(endPosition)) {
// current block cannot be at the same level as a preivous block
continue;
}
if (options.insertSpaces) {
return [
TextEdit.delete(new Range(startPosition, endPosition))
];
}
else {
// Delete everything before the block and insert the same characters we have in the previous block
const prefixOfPreviousBlock = prevLineText.substring(0, startOfBlockInLine);
const startDeletePosition = new Position(position.line, 0);
const endDeletePosition = new Position(position.line, line.firstNonWhitespaceCharacterIndex);
return [
TextEdit.delete(new Range(startDeletePosition, endDeletePosition)),
TextEdit.insert(startDeletePosition, prefixOfPreviousBlock)
];
}
}
return [];
}
示例2: findEndRange
protected findEndRange(document:TextDocument, anchor: Position): Range {
let matchingCount = 0;
let lineIndex = anchor.line;
do {
const lineText = document.lineAt(lineIndex).text;
let characterIndex = lineIndex === anchor.line ? anchor.character : 0;
while (characterIndex < lineText.length) {
if (lineText[characterIndex] === this.openingCharacter) {
// Don't count opening character on anchor.
if (! anchor.isEqual(new Position(lineIndex, characterIndex))) {
matchingCount++;
}
}
else if (lineText[characterIndex] === this.closingCharacter) {
if (matchingCount === 0) {
return new Range(
lineIndex, characterIndex,
lineIndex, characterIndex + 1
);
}
else {
matchingCount--;
}
}
characterIndex++;
}
lineIndex++;
} while (lineIndex < document.lineCount);
return null;
}
示例3: eatWhile
/**
* Repeatedly calls <code>eat</code> with the given argument, until it
* fails. Returns <code>true</code> if any characters were eaten.
* @param {Object} match
* @returns {Boolean}
*/
eatWhile(match) {
const start = this.pos;
while (!this.eof() && this.eat(match)) { }
return !this.pos.isEqual(start);
}
示例4: eatWhile
/**
* Repeatedly calls <code>eat</code> with the given argument, until it
* fails. Returns <code>true</code> if any characters were eaten.
*/
eatWhile(match: number | Function): boolean {
const start = this.pos;
while (!this.eof() && this.eat(match)) { }
return !this.pos.isEqual(start);
}