本文整理汇总了TypeScript中vs/editor/common/model.ITextModel类的典型用法代码示例。如果您正苦于以下问题:TypeScript ITextModel类的具体用法?TypeScript ITextModel怎么用?TypeScript ITextModel使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ITextModel类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: lineInsertAfter
public static lineInsertAfter(config: CursorConfiguration, model: ITextModel, selections: Selection[]): ICommand[] {
let commands: ICommand[] = [];
for (let i = 0, len = selections.length; i < len; i++) {
const lineNumber = selections[i].positionLineNumber;
let column = model.getLineMaxColumn(lineNumber);
commands[i] = this._enter(config, model, false, new Range(lineNumber, column, lineNumber, column));
}
return commands;
}
开发者ID:liunian,项目名称:vscode,代码行数:9,代码来源:cursorTypeOperations.ts
示例2: 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);
}
开发者ID:AllureFer,项目名称:vscode,代码行数:18,代码来源:transpose.ts
示例3: positionLeftOf
private positionLeftOf(start: IPosition, model: ITextModel): Position {
let column = start.column;
let lineNumber = start.lineNumber;
if (column > model.getLineMinColumn(lineNumber)) {
if (isLowSurrogate(model.getLineContent(lineNumber).charCodeAt(column - 2))) {
// character before column is a low surrogate
column = column - 2;
} else {
column = column - 1;
}
} else if (lineNumber > 1) {
lineNumber = lineNumber - 1;
column = model.getLineMaxColumn(lineNumber);
}
return new Position(lineNumber, column);
}
开发者ID:AllureFer,项目名称:vscode,代码行数:18,代码来源:transpose.ts
示例4: _attemptRemoveBlockComment
private _attemptRemoveBlockComment(model: ITextModel, s: Selection, startToken: string, endToken: string): IIdentifiedSingleEditOperation[] | null {
let startLineNumber = s.startLineNumber;
let endLineNumber = s.endLineNumber;
let startTokenAllowedBeforeColumn = endToken.length + Math.max(
model.getLineFirstNonWhitespaceColumn(s.startLineNumber),
s.startColumn
);
let startTokenIndex = model.getLineContent(startLineNumber).lastIndexOf(startToken, startTokenAllowedBeforeColumn - 1);
let endTokenIndex = model.getLineContent(endLineNumber).indexOf(endToken, s.endColumn - 1 - startToken.length);
if (startTokenIndex !== -1 && endTokenIndex === -1) {
endTokenIndex = model.getLineContent(startLineNumber).indexOf(endToken, startTokenIndex + startToken.length);
endLineNumber = startLineNumber;
}
if (startTokenIndex === -1 && endTokenIndex !== -1) {
startTokenIndex = model.getLineContent(endLineNumber).lastIndexOf(startToken, endTokenIndex);
startLineNumber = endLineNumber;
}
if (s.isEmpty() && (startTokenIndex === -1 || endTokenIndex === -1)) {
startTokenIndex = model.getLineContent(startLineNumber).indexOf(startToken);
if (startTokenIndex !== -1) {
endTokenIndex = model.getLineContent(startLineNumber).indexOf(endToken, startTokenIndex + startToken.length);
}
}
// We have to adjust to possible inner white space.
// For Space after startToken, add Space to startToken - range math will work out.
if (startTokenIndex !== -1 && model.getLineContent(startLineNumber).charCodeAt(startTokenIndex + startToken.length) === CharCode.Space) {
startToken += ' ';
}
// For Space before endToken, add Space before endToken and shift index one left.
if (endTokenIndex !== -1 && model.getLineContent(endLineNumber).charCodeAt(endTokenIndex - 1) === CharCode.Space) {
endToken = ' ' + endToken;
endTokenIndex -= 1;
}
if (startTokenIndex !== -1 && endTokenIndex !== -1) {
return BlockCommentCommand._createRemoveBlockCommentOperations(
new Range(startLineNumber, startTokenIndex + startToken.length + 1, endLineNumber, endTokenIndex + 1), startToken, endToken
);
}
return null;
}
开发者ID:DonJayamanne,项目名称:vscode,代码行数:49,代码来源:lineCommentCommand.ts
示例5: _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;
}
开发者ID:ramesius,项目名称:vscode,代码行数:44,代码来源:cursorTypeOperations.ts
示例6: toIndentRanges
public toIndentRanges(model: ITextModel) {
if (this._length <= this._foldingRangesLimit) {
// reverse and create arrays of the exact length
let startIndexes = new Uint32Array(this._length);
let endIndexes = new Uint32Array(this._length);
for (let i = this._length - 1, k = 0; i >= 0; i-- , k++) {
startIndexes[k] = this._startIndexes[i];
endIndexes[k] = this._endIndexes[i];
}
return new FoldingRegions(startIndexes, endIndexes);
} else {
let entries = 0;
let maxIndent = this._indentOccurrences.length;
for (let i = 0; i < this._indentOccurrences.length; i++) {
let n = this._indentOccurrences[i];
if (n) {
if (n + entries > this._foldingRangesLimit) {
maxIndent = i;
break;
}
entries += n;
}
}
const tabSize = model.getOptions().tabSize;
// reverse and create arrays of the exact length
let startIndexes = new Uint32Array(entries);
let endIndexes = new Uint32Array(entries);
for (let i = this._length - 1, k = 0; i >= 0; i--) {
let startIndex = this._startIndexes[i];
let lineContent = model.getLineContent(startIndex);
let indent = TextModel.computeIndentLevel(lineContent, tabSize);
if (indent < maxIndent) {
startIndexes[k] = startIndex;
endIndexes[k] = this._endIndexes[i];
k++;
}
}
return new FoldingRegions(startIndexes, endIndexes);
}
}
开发者ID:sameer-coder,项目名称:vscode,代码行数:41,代码来源:indentRangeProvider.ts
示例7: tab
public static tab(config: CursorConfiguration, model: ITextModel, selections: Selection[]): ICommand[] {
let commands: ICommand[] = [];
for (let i = 0, len = selections.length; i < len; i++) {
const selection = selections[i];
if (selection.isEmpty()) {
let lineText = model.getLineContent(selection.startLineNumber);
if (/^\s*$/.test(lineText) && model.isCheapToTokenize(selection.startLineNumber)) {
let goodIndent = this._goodIndentForLine(config, model, selection.startLineNumber);
goodIndent = goodIndent || '\t';
let possibleTypeText = config.normalizeIndentation(goodIndent);
if (!strings.startsWith(lineText, possibleTypeText)) {
commands[i] = new ReplaceCommand(new Range(selection.startLineNumber, 1, selection.startLineNumber, lineText.length + 1), possibleTypeText, true);
continue;
}
}
commands[i] = this._replaceJumpToNextIndent(config, model, selection, true);
} else {
if (selection.startLineNumber === selection.endLineNumber) {
let lineMaxColumn = model.getLineMaxColumn(selection.startLineNumber);
if (selection.startColumn !== 1 || selection.endColumn !== lineMaxColumn) {
// This is a single line selection that is not the entire line
commands[i] = this._replaceJumpToNextIndent(config, model, selection, false);
continue;
}
}
commands[i] = new ShiftCommand(selection, {
isUnshift: false,
tabSize: config.tabSize,
indentSize: config.indentSize,
insertSpaces: config.insertSpaces,
useTabStops: config.useTabStops
});
}
}
return commands;
}
开发者ID:PKRoma,项目名称:vscode,代码行数:41,代码来源:cursorTypeOperations.ts
示例8: 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)
);
}
开发者ID:AllureFer,项目名称:vscode,代码行数:21,代码来源:smartSnippetInserter.ts
示例9: sortLines
/**
* Generate commands for sorting lines on a model.
*/
function sortLines(model: ITextModel, selection: Selection, descending: boolean): IIdentifiedSingleEditOperation {
let data = getSortData(model, selection, descending);
if (!data) {
return null;
}
return EditOperation.replace(
new Range(data.startLineNumber, 1, data.endLineNumber, model.getLineMaxColumn(data.endLineNumber)),
data.after.join('\n')
);
}
开发者ID:AllureFer,项目名称:vscode,代码行数:15,代码来源:sortLinesCommand.ts
示例10: 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));
开发者ID:sameer-coder,项目名称:vscode,代码行数:10,代码来源:syntaxRangeProvider.ts
注:本文中的vs/editor/common/model.ITextModel类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论