本文整理汇总了TypeScript中vs/editor/common/model.ITextModel.getLineCount方法的典型用法代码示例。如果您正苦于以下问题:TypeScript ITextModel.getLineCount方法的具体用法?TypeScript ITextModel.getLineCount怎么用?TypeScript ITextModel.getLineCount使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类vs/editor/common/model.ITextModel
的用法示例。
在下文中一共展示了ITextModel.getLineCount方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: _delete
protected _delete(wordSeparators: WordCharacterClassifier, model: ITextModel, selection: Selection, whitespaceHeuristics: boolean, wordNavigationType: WordNavigationType): Range {
let r = WordOperations.deleteWordRight(wordSeparators, model, selection, whitespaceHeuristics, wordNavigationType);
if (r) {
return r;
}
const lineCount = model.getLineCount();
const maxColumn = model.getLineMaxColumn(lineCount);
return new Range(lineCount, maxColumn, lineCount, maxColumn);
}
示例2: asWinJsPromise
let promises = providers.map((provider, rank) => asWinJsPromise(token => provider.provideFoldingRanges(model, token)).then(list => {
if (list && Array.isArray(list.ranges)) {
let nLines = model.getLineCount();
for (let r of list.ranges) {
if (r.startLineNumber > 0 && r.endLineNumber > r.startLineNumber && r.endLineNumber <= nLines) {
rangeData.push({ startLineNumber: r.startLineNumber, endLineNumber: r.endLineNumber, rank, type: r.type });
}
}
}
}, onUnexpectedExternalError));
示例3: matchEnterRule
private matchEnterRule(model: ITextModel, indentConverter: IIndentConverter, tabSize: number, line: number, oneLineAbove: number, oneLineAboveText?: string) {
let validPrecedingLine = oneLineAbove;
while (validPrecedingLine >= 1) {
// ship empty lines as empty lines just inherit indentation
let lineContent;
if (validPrecedingLine === oneLineAbove && oneLineAboveText !== undefined) {
lineContent = oneLineAboveText;
} else {
lineContent = model.getLineContent(validPrecedingLine);
}
let nonWhitespaceIdx = strings.lastNonWhitespaceIndex(lineContent);
if (nonWhitespaceIdx >= 0) {
break;
}
validPrecedingLine--;
}
if (validPrecedingLine < 1 || line > model.getLineCount()) {
return null;
}
let maxColumn = model.getLineMaxColumn(validPrecedingLine);
let enter = LanguageConfigurationRegistry.getEnterAction(model, new Range(validPrecedingLine, maxColumn, validPrecedingLine, maxColumn));
if (enter) {
let enterPrefix = enter.indentation;
let enterAction = enter.enterAction;
if (enterAction.indentAction === IndentAction.None) {
enterPrefix = enter.indentation + enterAction.appendText;
} else if (enterAction.indentAction === IndentAction.Indent) {
enterPrefix = enter.indentation + enterAction.appendText;
} else if (enterAction.indentAction === IndentAction.IndentOutdent) {
enterPrefix = enter.indentation;
} else if (enterAction.indentAction === IndentAction.Outdent) {
enterPrefix = indentConverter.unshiftIndent(enter.indentation) + enterAction.appendText;
}
let movingLineText = model.getLineContent(line);
if (this.trimLeft(movingLineText).indexOf(this.trimLeft(enterPrefix)) >= 0) {
let oldIndentation = strings.getLeadingWhitespace(model.getLineContent(line));
let newIndentation = strings.getLeadingWhitespace(enterPrefix);
let indentMetadataOfMovelingLine = LanguageConfigurationRegistry.getIndentMetadata(model, line);
if (indentMetadataOfMovelingLine !== null && indentMetadataOfMovelingLine & IndentConsts.DECREASE_MASK) {
newIndentation = indentConverter.unshiftIndent(newIndentation);
}
let newSpaceCnt = indentUtils.getSpaceCnt(newIndentation, tabSize);
let oldSpaceCnt = indentUtils.getSpaceCnt(oldIndentation, tabSize);
return newSpaceCnt - oldSpaceCnt;
}
}
return null;
}
示例4: getEditOperations
public getEditOperations(model: ITextModel, builder: IEditOperationBuilder): void {
if (model.getLineCount() === 1 && model.getLineMaxColumn(1) === 1) {
// Model is empty
return;
}
var startLineNumber = this.startLineNumber;
var endLineNumber = this.endLineNumber;
var startColumn = 1;
var endColumn = model.getLineMaxColumn(endLineNumber);
if (endLineNumber < model.getLineCount()) {
endLineNumber += 1;
endColumn = 1;
} else if (startLineNumber > 1) {
startLineNumber -= 1;
startColumn = model.getLineMaxColumn(startLineNumber);
}
builder.addTrackedEditOperation(new Range(startLineNumber, startColumn, endLineNumber, endColumn), null);
}
示例5: toThenable
return toThenable(provider.provideFoldingRanges(model, foldingContext, cancellationToken)).then(ranges => {
if (cancellationToken.isCancellationRequested) {
return;
}
if (Array.isArray(ranges)) {
if (!Array.isArray(rangeData)) {
rangeData = [];
}
let nLines = model.getLineCount();
for (let r of ranges) {
if (r.start > 0 && r.end > r.start && r.end <= nLines) {
rangeData.push({ start: r.start, end: r.end, rank: i, kind: r.kind });
}
}
}
}, onUnexpectedExternalError);
示例6: positionRightOf
private positionRightOf(start: IPosition, model: ITextModel): Position {
let column = start.column;
let lineNumber = start.lineNumber;
if (column < model.getLineMaxColumn(lineNumber)) {
if (isHighSurrogate(model.getLineContent(lineNumber).charCodeAt(column - 1))) {
// character after column is a high surrogate
column = column + 2;
} else {
column = column + 1;
}
} else if (lineNumber < model.getLineCount()) {
lineNumber = lineNumber + 1;
column = 0;
}
return new Position(lineNumber, column);
}
示例7: offsetToPosition
private static offsetToPosition(model: ITextModel, offset: number): Position {
let offsetBeforeLine = 0;
let eolLength = model.getEOL().length;
let lineCount = model.getLineCount();
for (let lineNumber = 1; lineNumber <= lineCount; lineNumber++) {
let lineTotalLength = model.getLineContent(lineNumber).length + eolLength;
let offsetAfterLine = offsetBeforeLine + lineTotalLength;
if (offsetAfterLine > offset) {
return new Position(
lineNumber,
offset - offsetBeforeLine + 1
);
}
offsetBeforeLine = offsetAfterLine;
}
return new Position(
lineCount,
model.getLineMaxColumn(lineCount)
);
}
示例8:
return TPromise.join(promises).then(results => {
let rangeData: IFoldingRangeData[] = null;
if (cancellationToken.isCancellationRequested) {
return null;
}
for (let i = 0; i < results.length; i++) {
let ranges = results[i];
if (Array.isArray(ranges)) {
if (!Array.isArray(rangeData)) {
rangeData = [];
}
let nLines = model.getLineCount();
for (let r of ranges) {
if (r.start > 0 && r.end > r.start && r.end <= nLines) {
rangeData.push({ start: r.start, end: r.end, rank: i, kind: r.kind });
}
}
}
}
return rangeData;
}, onUnexpectedExternalError);
示例9:
return TPromise.join(promises).then(lists => {
let rangeData: IFoldingRangeData[] = null;
if (cancellationToken.isCancellationRequested) {
return null;
}
for (let i = 0; i < lists.length; i++) {
let list = lists[i];
if (list && Array.isArray(list.ranges)) {
if (!Array.isArray(rangeData)) {
rangeData = [];
}
let nLines = model.getLineCount();
for (let r of list.ranges) {
if (r.startLineNumber > 0 && r.endLineNumber > r.startLineNumber && r.endLineNumber <= nLines) {
rangeData.push({ startLineNumber: r.startLineNumber, endLineNumber: r.endLineNumber, rank: i, type: r.type });
}
}
}
}
return rangeData;
}, onUnexpectedExternalError);
示例10: trimTrailingWhitespace
export function trimTrailingWhitespace(model: ITextModel, cursors: Position[]): IIdentifiedSingleEditOperation[] {
// Sort cursors ascending
cursors.sort((a, b) => {
if (a.lineNumber === b.lineNumber) {
return a.column - b.column;
}
return a.lineNumber - b.lineNumber;
});
// Reduce multiple cursors on the same line and only keep the last one on the line
for (let i = cursors.length - 2; i >= 0; i--) {
if (cursors[i].lineNumber === cursors[i + 1].lineNumber) {
// Remove cursor at `i`
cursors.splice(i, 1);
}
}
let r: IIdentifiedSingleEditOperation[] = [];
let rLen = 0;
let cursorIndex = 0;
let cursorLen = cursors.length;
for (let lineNumber = 1, lineCount = model.getLineCount(); lineNumber <= lineCount; lineNumber++) {
let lineContent = model.getLineContent(lineNumber);
let maxLineColumn = lineContent.length + 1;
let minEditColumn = 0;
if (cursorIndex < cursorLen && cursors[cursorIndex].lineNumber === lineNumber) {
minEditColumn = cursors[cursorIndex].column;
cursorIndex++;
if (minEditColumn === maxLineColumn) {
// The cursor is at the end of the line => no edits for sure on this line
continue;
}
}
if (lineContent.length === 0) {
continue;
}
let lastNonWhitespaceIndex = strings.lastNonWhitespaceIndex(lineContent);
let fromColumn = 0;
if (lastNonWhitespaceIndex === -1) {
// Entire line is whitespace
fromColumn = 1;
} else if (lastNonWhitespaceIndex !== lineContent.length - 1) {
// There is trailing whitespace
fromColumn = lastNonWhitespaceIndex + 2;
} else {
// There is no trailing whitespace
continue;
}
fromColumn = Math.max(minEditColumn, fromColumn);
r[rLen++] = EditOperation.delete(new Range(
lineNumber, fromColumn,
lineNumber, maxLineColumn
));
}
return r;
}