本文整理汇总了TypeScript中vs/base/common/strings.commonPrefixLength函数的典型用法代码示例。如果您正苦于以下问题:TypeScript commonPrefixLength函数的具体用法?TypeScript commonPrefixLength怎么用?TypeScript commonPrefixLength使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了commonPrefixLength函数的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: resolve
resolve(variable: Variable): string {
const { name } = variable;
if (name === 'SELECTION' || name === 'TM_SELECTED_TEXT') {
let value = this._model.getValueInRange(this._selection) || undefined;
if (value && this._selection.startLineNumber !== this._selection.endLineNumber) {
// Selection is a multiline string which we indentation we now
// need to adjust. We compare the indentation of this variable
// with the indentation at the editor position and add potential
// extra indentation to the value
const line = this._model.getLineContent(this._selection.startLineNumber);
const lineLeadingWhitespace = getLeadingWhitespace(line, 0, this._selection.startColumn - 1);
let varLeadingWhitespace = lineLeadingWhitespace;
variable.snippet.walk(marker => {
if (marker === variable) {
return false;
}
if (marker instanceof Text) {
varLeadingWhitespace = getLeadingWhitespace(marker.value.split(/\r\n|\r|\n/).pop());
}
return true;
});
const whitespaceCommonLength = commonPrefixLength(varLeadingWhitespace, lineLeadingWhitespace);
value = value.replace(
/(\r\n|\r|\n)(.*)/g,
(m, newline, rest) => `${newline}${varLeadingWhitespace.substr(whitespaceCommonLength)}${rest}`
);
}
return value;
} else if (name === 'TM_CURRENT_LINE') {
return this._model.getLineContent(this._selection.positionLineNumber);
} else if (name === 'TM_CURRENT_WORD') {
const info = this._model.getWordAtPosition({
lineNumber: this._selection.positionLineNumber,
column: this._selection.positionColumn
});
return info && info.word || undefined;
} else if (name === 'TM_LINE_INDEX') {
return String(this._selection.positionLineNumber - 1);
} else if (name === 'TM_LINE_NUMBER') {
return String(this._selection.positionLineNumber);
}
return undefined;
}
开发者ID:servicesgpr,项目名称:vscode,代码行数:52,代码来源:snippetVariables.ts
示例2: _trimEdit
static _trimEdit(editRange: Range, editText: string, editForceMoveMarkers: boolean, model: editorCommon.ITokenizedModel): editorCommon.ISingleEditOperation {
let currentText = model.getValueInRange(editRange);
// Find the equal characters in the front
let commonPrefixLength = strings.commonPrefixLength(editText, currentText);
// If the two strings are identical, return no edit (no-op)
if (commonPrefixLength === currentText.length && commonPrefixLength === editText.length) {
return null;
}
if (commonPrefixLength > 0) {
// Apply front trimming
let newStartPosition = model.modifyPosition(editRange.getStartPosition(), commonPrefixLength);
editRange = new Range(newStartPosition.lineNumber, newStartPosition.column, editRange.endLineNumber, editRange.endColumn);
editText = editText.substring(commonPrefixLength);
currentText = currentText.substr(commonPrefixLength);
}
// Find the equal characters in the rear
let commonSuffixLength = strings.commonSuffixLength(editText, currentText);
if (commonSuffixLength > 0) {
// Apply rear trimming
let newEndPosition = model.modifyPosition(editRange.getEndPosition(), -commonSuffixLength);
editRange = new Range(editRange.startLineNumber, editRange.startColumn, newEndPosition.lineNumber, newEndPosition.column);
editText = editText.substring(0, editText.length - commonSuffixLength);
currentText = currentText.substring(0, currentText.length - commonSuffixLength);
}
return {
text: editText,
range: editRange,
forceMoveMarkers: editForceMoveMarkers
};
}
开发者ID:AlexxNica,项目名称:sqlopsstudio,代码行数:37,代码来源:formatCommand.ts
注:本文中的vs/base/common/strings.commonPrefixLength函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论