本文整理匯總了TypeScript中vs/base/common/strings.lastNonWhitespaceIndex函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript lastNonWhitespaceIndex函數的具體用法?TypeScript lastNonWhitespaceIndex怎麽用?TypeScript lastNonWhitespaceIndex使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了lastNonWhitespaceIndex函數的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: getLineLastNonWhitespaceColumn
public getLineLastNonWhitespaceColumn(lineNumber: number): number {
const result = strings.lastNonWhitespaceIndex(this.getLineContent(lineNumber));
if (result === -1) {
return 0;
}
return result + 2;
}
示例2: _getLastNonBlankColumn
public static _getLastNonBlankColumn(txt: string, defaultValue: number): number {
const r = strings.lastNonWhitespaceIndex(txt);
if (r === -1) {
return defaultValue;
}
return r + 2;
}
示例3: getLineLastNonWhitespaceColumn
getLineLastNonWhitespaceColumn(lineNumber: number): number {
let result = strings.lastNonWhitespaceIndex(this._line);
if (result === -1) {
return 0;
}
return result + 2;
}
示例4: _deleteWordLeftWhitespace
protected static _deleteWordLeftWhitespace(model: ICursorSimpleModel, position: Position): Range {
const lineContent = model.getLineContent(position.lineNumber);
const startIndex = position.column - 2;
const lastNonWhitespace = strings.lastNonWhitespaceIndex(lineContent, startIndex);
if (lastNonWhitespace + 1 < startIndex) {
return new Range(position.lineNumber, lastNonWhitespace + 2, position.lineNumber, position.column);
}
return null;
}
示例5: containNonWhitespace
public containNonWhitespace(text: string): boolean {
// the text doesn't contain any non-whitespace character.
let nonWhitespaceIdx = strings.lastNonWhitespaceIndex(text);
if (nonWhitespaceIdx >= 0) {
return true;
}
return false;
}
示例6: 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;
}
示例7: _goodIndentForLine
private static _goodIndentForLine(config: CursorConfiguration, model: ITextModel, lineNumber: number): string {
let action: IndentAction | EnterAction;
let indentation: string;
let expectedIndentAction = config.autoIndent ? LanguageConfigurationRegistry.getInheritIndentForLine(model, lineNumber, false) : null;
if (expectedIndentAction) {
action = expectedIndentAction.action;
indentation = expectedIndentAction.indentation;
} else if (lineNumber > 1) {
let lastLineNumber = lineNumber - 1;
for (lastLineNumber = lineNumber - 1; lastLineNumber >= 1; lastLineNumber--) {
let lineText = model.getLineContent(lastLineNumber);
let nonWhitespaceIdx = strings.lastNonWhitespaceIndex(lineText);
if (nonWhitespaceIdx >= 0) {
break;
}
}
if (lastLineNumber < 1) {
// No previous line with content found
return null;
}
let maxColumn = model.getLineMaxColumn(lastLineNumber);
let expectedEnterAction = LanguageConfigurationRegistry.getEnterAction(model, new Range(lastLineNumber, maxColumn, lastLineNumber, maxColumn));
if (expectedEnterAction) {
indentation = expectedEnterAction.indentation;
action = expectedEnterAction.enterAction;
if (action) {
indentation += action.appendText;
}
}
}
if (action) {
if (action === IndentAction.Indent) {
indentation = TypeOperations.shiftIndent(config, indentation);
}
if (action === IndentAction.Outdent) {
indentation = TypeOperations.unshiftIndent(config, indentation);
}
indentation = config.normalizeIndentation(indentation);
}
if (!indentation) {
return null;
}
return indentation;
}
示例8: getLineLastNonWhitespaceColumn
public getLineLastNonWhitespaceColumn(lineNumber: number): number {
if (this._isDisposed) {
throw new Error('TextModel.getLineLastNonWhitespaceColumn: Model is disposed');
}
if (lineNumber < 1 || lineNumber > this.getLineCount()) {
throw new Error('Illegal value ' + lineNumber + ' for `lineNumber`');
}
var result = strings.lastNonWhitespaceIndex(this._lines[lineNumber - 1].text);
if (result === -1) {
return 0;
}
return result + 2;
}
示例9: _deleteWordLeftWhitespace
private static _deleteWordLeftWhitespace(config: CursorConfiguration, model: ICursorSimpleModel, cursor: SingleCursorState): EditOperationResult {
let position = cursor.position;
let lineContent = model.getLineContent(position.lineNumber);
let startIndex = position.column - 2;
let lastNonWhitespace = strings.lastNonWhitespaceIndex(lineContent, startIndex);
if (lastNonWhitespace + 1 < startIndex) {
let deleteRange = new Range(position.lineNumber, lastNonWhitespace + 2, position.lineNumber, position.column);
return new EditOperationResult(new ReplaceCommand(deleteRange, ''), {
shouldPushStackElementBefore: false,
shouldPushStackElementAfter: false
});
}
return null;
}
示例10: _goodIndentForLine
private static _goodIndentForLine(config: CursorConfiguration, model: ITokenizedModel, lineNumber: number): string {
let lastLineNumber = lineNumber - 1;
for (lastLineNumber = lineNumber - 1; lastLineNumber >= 1; lastLineNumber--) {
let lineText = model.getLineContent(lastLineNumber);
let nonWhitespaceIdx = strings.lastNonWhitespaceIndex(lineText);
if (nonWhitespaceIdx >= 0) {
break;
}
}
if (lastLineNumber < 1) {
// No previous line with content found
return '\t';
}
let r = LanguageConfigurationRegistry.getEnterActionAtPosition(model, lastLineNumber, model.getLineMaxColumn(lastLineNumber));
let indentation: string;
if (r.enterAction.indentAction === IndentAction.Outdent) {
let desiredIndentCount = ShiftCommand.unshiftIndentCount(r.indentation, r.indentation.length, config.tabSize);
indentation = '';
for (let i = 0; i < desiredIndentCount; i++) {
indentation += '\t';
}
indentation = config.normalizeIndentation(indentation);
} else {
indentation = r.indentation;
}
let result = indentation + r.enterAction.appendText;
if (result.length === 0) {
// good position is at column 1, but we gotta do something...
return '\t';
}
return result;
}