本文整理汇总了TypeScript中vs/editor/common/model/textModel.TextModel.getPositionAt方法的典型用法代码示例。如果您正苦于以下问题:TypeScript TextModel.getPositionAt方法的具体用法?TypeScript TextModel.getPositionAt怎么用?TypeScript TextModel.getPositionAt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类vs/editor/common/model/textModel.TextModel
的用法示例。
在下文中一共展示了TextModel.getPositionAt方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: _getMultilineMatchRange
/**
* Multiline search always executes on the lines concatenated with \n.
* We must therefore compensate for the count of \n in case the model is CRLF
*/
private static _getMultilineMatchRange(model: TextModel, deltaOffset: number, text: string, matchIndex: number, match0: string): Range {
let startOffset: number;
if (model.getEOL() === '\r\n') {
let lineFeedCountBeforeMatch = 0;
for (let i = 0; i < matchIndex; i++) {
let chCode = text.charCodeAt(i);
if (chCode === CharCode.LineFeed) {
lineFeedCountBeforeMatch++;
}
}
startOffset = deltaOffset + matchIndex + lineFeedCountBeforeMatch /* add as many \r as there were \n */;
} else {
startOffset = deltaOffset + matchIndex;
}
let endOffset: number;
if (model.getEOL() === '\r\n') {
let lineFeedCountInMatch = 0;
for (let i = 0, len = match0.length; i < len; i++) {
let chCode = text.charCodeAt(i + matchIndex);
if (chCode === CharCode.LineFeed) {
lineFeedCountInMatch++;
}
}
endOffset = startOffset + match0.length + lineFeedCountInMatch /* add as many \r as there were \n */;
} else {
endOffset = startOffset + match0.length;
}
const startPosition = model.getPositionAt(startOffset);
const endPosition = model.getPositionAt(endOffset);
return new Range(startPosition.lineNumber, startPosition.column, endPosition.lineNumber, endPosition.column);
}
示例2: _doFindNextMatchMultiline
private static _doFindNextMatchMultiline(model: TextModel, searchStart: Position, searchRegex: RegExp, captureMatches: boolean): FindMatch {
const searchTextStart = new Position(searchStart.lineNumber, 1);
const deltaOffset = model.getOffsetAt(searchTextStart);
const lineCount = model.getLineCount();
const text = model.getValueInRange(new Range(searchTextStart.lineNumber, searchTextStart.column, lineCount, model.getLineMaxColumn(lineCount)));
searchRegex.lastIndex = searchStart.column - 1;
let m = searchRegex.exec(text);
if (m) {
const startOffset = deltaOffset + m.index;
const endOffset = startOffset + m[0].length;
const startPosition = model.getPositionAt(startOffset);
const endPosition = model.getPositionAt(endOffset);
return createFindMatch(
new Range(startPosition.lineNumber, startPosition.column, endPosition.lineNumber, endPosition.column),
m,
captureMatches
);
}
if (searchStart.lineNumber !== 1 || searchStart.column !== -1) {
// Try again from the top
return this._doFindNextMatchMultiline(model, new Position(1, 1), searchRegex, captureMatches);
}
return null;
}
示例3: assertOneDirectionLineMapping
function assertOneDirectionLineMapping(model: TextModel, direction: AssertDocumentLineMappingDirection, msg: string): void {
let allText = model.getValue();
let line = 1, column = 1, previousIsCarriageReturn = false;
for (let offset = 0; offset <= allText.length; offset++) {
// The position coordinate system cannot express the position between \r and \n
let position = new Position(line, column + (previousIsCarriageReturn ? -1 : 0));
if (direction === AssertDocumentLineMappingDirection.OffsetToPosition) {
let actualPosition = model.getPositionAt(offset);
assert.equal(actualPosition.toString(), position.toString(), msg + ' - getPositionAt mismatch for offset ' + offset);
} else {
// The position coordinate system cannot express the position between \r and \n
let expectedOffset = offset + (previousIsCarriageReturn ? -1 : 0);
let actualOffset = model.getOffsetAt(position);
assert.equal(actualOffset, expectedOffset, msg + ' - getOffsetAt mismatch for position ' + position.toString());
}
if (allText.charAt(offset) === '\n') {
line++;
column = 1;
} else {
column++;
}
previousIsCarriageReturn = (allText.charAt(offset) === '\r');
}
}
示例4: _getMultilineMatchRange
/**
* Multiline search always executes on the lines concatenated with \n.
* We must therefore compensate for the count of \n in case the model is CRLF
*/
private static _getMultilineMatchRange(model: TextModel, deltaOffset: number, text: string, lfCounter: LineFeedCounter | null, matchIndex: number, match0: string): Range {
let startOffset: number;
let lineFeedCountBeforeMatch = 0;
if (lfCounter) {
lineFeedCountBeforeMatch = lfCounter.findLineFeedCountBeforeOffset(matchIndex);
startOffset = deltaOffset + matchIndex + lineFeedCountBeforeMatch /* add as many \r as there were \n */;
} else {
startOffset = deltaOffset + matchIndex;
}
let endOffset: number;
if (lfCounter) {
let lineFeedCountBeforeEndOfMatch = lfCounter.findLineFeedCountBeforeOffset(matchIndex + match0.length);
let lineFeedCountInMatch = lineFeedCountBeforeEndOfMatch - lineFeedCountBeforeMatch;
endOffset = startOffset + match0.length + lineFeedCountInMatch /* add as many \r as there were \n */;
} else {
endOffset = startOffset + match0.length;
}
const startPosition = model.getPositionAt(startOffset);
const endPosition = model.getPositionAt(endOffset);
return new Range(startPosition.lineNumber, startPosition.column, endPosition.lineNumber, endPosition.column);
}
示例5: _doFindMatchesMultiline
private static _doFindMatchesMultiline(model: TextModel, searchRange: Range, searchRegex: RegExp, captureMatches: boolean, limitResultCount: number): FindMatch[] {
const deltaOffset = model.getOffsetAt(searchRange.getStartPosition());
const text = model.getValueInRange(searchRange);
const result: FindMatch[] = [];
let prevStartOffset = 0;
let prevEndOffset = 0;
let counter = 0;
let m: RegExpExecArray;
while ((m = searchRegex.exec(text))) {
const startOffset = deltaOffset + m.index;
const endOffset = startOffset + m[0].length;
if (prevStartOffset === startOffset && prevEndOffset === endOffset) {
// Exit early if the regex matches the same range
return result;
}
const startPosition = model.getPositionAt(startOffset);
const endPosition = model.getPositionAt(endOffset);
result[counter++] = createFindMatch(
new Range(startPosition.lineNumber, startPosition.column, endPosition.lineNumber, endPosition.column),
m,
captureMatches
);
if (counter >= limitResultCount) {
return result;
}
prevStartOffset = startOffset;
prevEndOffset = endOffset;
}
return result;
}