本文整理汇总了TypeScript中vs/editor/common/editorCommon.ITokenizedModel.getLineCount方法的典型用法代码示例。如果您正苦于以下问题:TypeScript ITokenizedModel.getLineCount方法的具体用法?TypeScript ITokenizedModel.getLineCount怎么用?TypeScript ITokenizedModel.getLineCount使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类vs/editor/common/editorCommon.ITokenizedModel
的用法示例。
在下文中一共展示了ITokenizedModel.getLineCount方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: getIndentationEditOperations
function getIndentationEditOperations(model: ITokenizedModel, builder: IEditOperationBuilder, tabSize: number, tabsToSpaces: boolean): void {
if (model.getLineCount() === 1 && model.getLineMaxColumn(1) === 1) {
// Model is empty
return;
}
let spaces = '';
for (let i = 0; i < tabSize; i++) {
spaces += ' ';
}
const content = model.getLinesContent();
for (let i = 0; i < content.length; i++) {
let lastIndentationColumn = model.getLineFirstNonWhitespaceColumn(i + 1);
if (lastIndentationColumn === 0) {
lastIndentationColumn = model.getLineMaxColumn(i + 1);
}
const text = (tabsToSpaces ? content[i].substr(0, lastIndentationColumn).replace(/\t/ig, spaces) :
content[i].substr(0, lastIndentationColumn).replace(new RegExp(spaces, 'gi'), '\t')) +
content[i].substr(lastIndentationColumn);
builder.addEditOperation(new Range(i + 1, 1, i + 1, model.getLineMaxColumn(i + 1)), text);
}
}
示例2: matchEnterRule
private matchEnterRule(model: ITokenizedModel, 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 & IndentConsts.DECREASE_MASK) {
newIndentation = indentConverter.unshiftIndent(newIndentation);
}
let newSpaceCnt = IndentUtil.getSpaceCnt(newIndentation, tabSize);
let oldSpaceCnt = IndentUtil.getSpaceCnt(oldIndentation, tabSize);
return newSpaceCnt - oldSpaceCnt;
}
}
return null;
}
示例3: getEditOperations
public getEditOperations(model: ITokenizedModel, 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);
}
示例4: getEditOperations
public getEditOperations(model: ITokenizedModel, builder: IEditOperationBuilder): void {
var modelLineCount = model.getLineCount();
if (this._isMovingDown && this._selection.endLineNumber === modelLineCount) {
return;
}
if (!this._isMovingDown && this._selection.startLineNumber === 1) {
return;
}
this._moveEndPositionDown = false;
var s = this._selection;
if (s.startLineNumber < s.endLineNumber && s.endColumn === 1) {
this._moveEndPositionDown = true;
s = s.setEndPosition(s.endLineNumber - 1, model.getLineMaxColumn(s.endLineNumber - 1));
}
let tabSize = model.getOptions().tabSize;
let insertSpaces = model.getOptions().insertSpaces;
let indentConverter = this.buildIndentConverter(tabSize);
let virtualModel = {
getLineTokens: (lineNumber: number) => {
return model.getLineTokens(lineNumber);
},
getLanguageIdentifier: () => {
return model.getLanguageIdentifier();
},
getLanguageIdAtPosition: (lineNumber: number, column: number) => {
return model.getLanguageIdAtPosition(lineNumber, column);
},
getLineContent: null
};
if (s.startLineNumber === s.endLineNumber && model.getLineMaxColumn(s.startLineNumber) === 1) {
// Current line is empty
var lineNumber = s.startLineNumber;
var otherLineNumber = (this._isMovingDown ? lineNumber + 1 : lineNumber - 1);
if (model.getLineMaxColumn(otherLineNumber) === 1) {
// Other line number is empty too, so no editing is needed
// Add a no-op to force running by the model
builder.addEditOperation(new Range(1, 1, 1, 1), null);
} else {
// Type content from other line number on line number
builder.addEditOperation(new Range(lineNumber, 1, lineNumber, 1), model.getLineContent(otherLineNumber));
// Remove content from other line number
builder.addEditOperation(new Range(otherLineNumber, 1, otherLineNumber, model.getLineMaxColumn(otherLineNumber)), null);
}
// Track selection at the other line number
s = new Selection(otherLineNumber, 1, otherLineNumber, 1);
} else {
var movingLineNumber: number,
movingLineText: string;
if (this._isMovingDown) {
movingLineNumber = s.endLineNumber + 1;
movingLineText = model.getLineContent(movingLineNumber);
// Delete line that needs to be moved
builder.addEditOperation(new Range(movingLineNumber - 1, model.getLineMaxColumn(movingLineNumber - 1), movingLineNumber, model.getLineMaxColumn(movingLineNumber)), null);
let insertingText = movingLineText;
if (this.shouldAutoIndent(model, s)) {
let movingLineMatchResult = this.matchEnterRule(model, indentConverter, tabSize, movingLineNumber, s.startLineNumber - 1);
// if s.startLineNumber - 1 matches onEnter rule, we still honor that.
if (movingLineMatchResult !== null) {
let oldIndentation = strings.getLeadingWhitespace(model.getLineContent(movingLineNumber));
let newSpaceCnt = movingLineMatchResult + IndentUtil.getSpaceCnt(oldIndentation, tabSize);
let newIndentation = IndentUtil.generateIndent(newSpaceCnt, tabSize, insertSpaces);
insertingText = newIndentation + this.trimLeft(movingLineText);
} else {
// no enter rule matches, let's check indentatin rules then.
virtualModel.getLineContent = (lineNumber: number) => {
if (lineNumber === s.startLineNumber) {
return model.getLineContent(movingLineNumber);
} else {
return model.getLineContent(lineNumber);
}
};
let indentOfMovingLine = LanguageConfigurationRegistry.getGoodIndentForLine(virtualModel, model.getLanguageIdAtPosition(
movingLineNumber, 1), s.startLineNumber, indentConverter);
if (indentOfMovingLine !== null) {
let oldIndentation = strings.getLeadingWhitespace(model.getLineContent(movingLineNumber));
let newSpaceCnt = IndentUtil.getSpaceCnt(indentOfMovingLine, tabSize);
let oldSpaceCnt = IndentUtil.getSpaceCnt(oldIndentation, tabSize);
if (newSpaceCnt !== oldSpaceCnt) {
let newIndentation = IndentUtil.generateIndent(newSpaceCnt, tabSize, insertSpaces);
insertingText = newIndentation + this.trimLeft(movingLineText);
}
}
}
// add edit operations for moving line first to make sure it's executed after we make indentation change
// to s.startLineNumber
builder.addEditOperation(new Range(s.startLineNumber, 1, s.startLineNumber, 1), insertingText + '\n');
//.........这里部分代码省略.........
示例5: getEditOperations
public getEditOperations(model:ITokenizedModel, builder:IEditOperationBuilder):void {
var modelLineCount = model.getLineCount();
if (this._isMovingDown && this._selection.endLineNumber === modelLineCount) {
return;
}
if (!this._isMovingDown && this._selection.startLineNumber === 1) {
return;
}
this._moveEndPositionDown = false;
var s = this._selection;
if (s.startLineNumber < s.endLineNumber && s.endColumn === 1) {
this._moveEndPositionDown = true;
s = s.setEndPosition(s.endLineNumber - 1, model.getLineMaxColumn(s.endLineNumber - 1));
}
if (s.startLineNumber === s.endLineNumber && model.getLineMaxColumn(s.startLineNumber) === 1) {
// Current line is empty
var lineNumber = s.startLineNumber;
var otherLineNumber = (this._isMovingDown ? lineNumber + 1 : lineNumber - 1);
if (model.getLineMaxColumn(otherLineNumber) === 1) {
// Other line number is empty too, so no editing is needed
// Add a no-op to force running by the model
builder.addEditOperation(new Range(1, 1, 1, 1), null);
} else {
// Type content from other line number on line number
builder.addEditOperation(new Range(lineNumber, 1, lineNumber, 1), model.getLineContent(otherLineNumber));
// Remove content from other line number
builder.addEditOperation(new Range(otherLineNumber, 1, otherLineNumber, model.getLineMaxColumn(otherLineNumber)), null);
}
// Track selection at the other line number
s = Selection.createSelection(otherLineNumber, 1, otherLineNumber, 1);
} else {
var movingLineNumber: number,
movingLineText: string;
if (this._isMovingDown) {
movingLineNumber = s.endLineNumber + 1;
movingLineText = model.getLineContent(movingLineNumber);
// Delete line that needs to be moved
builder.addEditOperation(new Range(movingLineNumber - 1, model.getLineMaxColumn(movingLineNumber - 1), movingLineNumber, model.getLineMaxColumn(movingLineNumber)), null);
// Insert line that needs to be moved before
builder.addEditOperation(new Range(s.startLineNumber, 1, s.startLineNumber, 1), movingLineText + '\n');
} else {
movingLineNumber = s.startLineNumber - 1;
movingLineText = model.getLineContent(movingLineNumber);
// Delete line that needs to be moved
builder.addEditOperation(new Range(movingLineNumber, 1, movingLineNumber + 1, 1), null);
// Insert line that needs to be moved after
builder.addEditOperation(new Range(s.endLineNumber, model.getLineMaxColumn(s.endLineNumber), s.endLineNumber, model.getLineMaxColumn(s.endLineNumber)), '\n' + movingLineText);
}
}
this._selectionId = builder.trackSelection(s);
}
示例6: joinLines
public static joinLines(config: CursorConfiguration, model: ITokenizedModel, cursor: SingleCursorState): EditOperationResult {
let selection = cursor.selection;
let position = cursor.position;
let startLineNumber: number,
startColumn: number,
endLineNumber: number,
endColumn: number,
columnDeltaOffset;
if (selection.isEmpty() || selection.startLineNumber === selection.endLineNumber) {
if (position.lineNumber < model.getLineCount()) {
startLineNumber = position.lineNumber;
startColumn = 1;
endLineNumber = startLineNumber + 1;
endColumn = model.getLineMaxColumn(endLineNumber);
} else {
startLineNumber = position.lineNumber;
startColumn = 1;
endLineNumber = position.lineNumber;
endColumn = model.getLineMaxColumn(position.lineNumber);
}
} else {
startLineNumber = selection.startLineNumber;
startColumn = 1;
endLineNumber = selection.endLineNumber;
endColumn = model.getLineMaxColumn(endLineNumber);
}
let trimmedLinesContent = model.getLineContent(startLineNumber);
for (let i = startLineNumber + 1; i <= endLineNumber; i++) {
let lineText = model.getLineContent(i);
let firstNonWhitespaceIdx = strings.firstNonWhitespaceIndex(lineText);
if (firstNonWhitespaceIdx >= 0) {
let insertSpace = true;
if (trimmedLinesContent === '' || trimmedLinesContent.charAt(trimmedLinesContent.length - 1) === ' ') {
insertSpace = false;
}
let lineTextWithoutIndent = lineText.substr(firstNonWhitespaceIdx);
if (lineTextWithoutIndent.charAt(0) === ')') {
insertSpace = false;
}
trimmedLinesContent += (insertSpace ? ' ' : '') + lineTextWithoutIndent;
if (insertSpace) {
columnDeltaOffset = lineTextWithoutIndent.length + 1;
} else {
columnDeltaOffset = lineTextWithoutIndent.length;
}
} else {
columnDeltaOffset = 0;
}
}
let deleteSelection = new Range(
startLineNumber,
startColumn,
endLineNumber,
endColumn
);
if (!deleteSelection.isEmpty()) {
if (!selection.isEmpty() && selection.startLineNumber === selection.endLineNumber) {
return new EditOperationResult(new ReplaceCommandThatPreservesSelection(deleteSelection, trimmedLinesContent, selection), {
shouldPushStackElementBefore: false,
shouldPushStackElementAfter: false
});
} else {
return new EditOperationResult(new ReplaceCommandWithOffsetCursorState(deleteSelection, trimmedLinesContent, 0, -columnDeltaOffset), {
shouldPushStackElementBefore: false,
shouldPushStackElementAfter: false
});
}
}
return null;
}