本文整理汇总了TypeScript中vs/editor/common/core/range.Range.getStartPosition方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Range.getStartPosition方法的具体用法?TypeScript Range.getStartPosition怎么用?TypeScript Range.getStartPosition使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类vs/editor/common/core/range.Range
的用法示例。
在下文中一共展示了Range.getStartPosition方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: deleteWordPartLeft
public static deleteWordPartLeft(wordSeparators: WordCharacterClassifier, model: ICursorSimpleModel, selection: Selection, whitespaceHeuristics: boolean, wordNavigationType: WordNavigationType): Range {
if (!selection.isEmpty()) {
return selection;
}
const position = new Position(selection.positionLineNumber, selection.positionColumn);
const lineNumber = position.lineNumber;
const column = position.column;
if (lineNumber === 1 && column === 1) {
// Ignore deleting at beginning of file
return null;
}
if (whitespaceHeuristics) {
let r = WordOperations._deleteWordLeftWhitespace(model, position);
if (r) {
return r;
}
}
const wordRange = WordOperations.deleteWordLeft(wordSeparators, model, selection, whitespaceHeuristics, wordNavigationType);
const lastWordPartEnd = _lastWordPartEnd(model.getLineContent(position.lineNumber), position.column - 2);
const wordPartRange = new Range(lineNumber, column, lineNumber, lastWordPartEnd + 2);
if (wordPartRange.getStartPosition().isBeforeOrEqual(wordRange.getStartPosition())) {
return wordRange;
}
return wordPartRange;
}
示例2: _computeSelection
private static _computeSelection(selectionStart: Range, position: Position): Selection {
let startLineNumber: number, startColumn: number, endLineNumber: number, endColumn: number;
if (selectionStart.isEmpty()) {
startLineNumber = selectionStart.startLineNumber;
startColumn = selectionStart.startColumn;
endLineNumber = position.lineNumber;
endColumn = position.column;
} else {
if (position.isBeforeOrEqual(selectionStart.getStartPosition())) {
startLineNumber = selectionStart.endLineNumber;
startColumn = selectionStart.endColumn;
endLineNumber = position.lineNumber;
endColumn = position.column;
} else {
startLineNumber = selectionStart.startLineNumber;
startColumn = selectionStart.startColumn;
endLineNumber = position.lineNumber;
endColumn = position.column;
}
}
return new Selection(
startLineNumber,
startColumn,
endLineNumber,
endColumn
);
}
示例3: _doFindMatchesMultiline
private static _doFindMatchesMultiline(model: TextModel, searchRange: Range, searcher: Searcher, captureMatches: boolean, limitResultCount: number): FindMatch[] {
const deltaOffset = model.getOffsetAt(searchRange.getStartPosition());
// We always execute multiline search over the lines joined with \n
// This makes it that \n will match the EOL for both CRLF and LF models
// We compensate for offset errors in `_getMultilineMatchRange`
const text = model.getValueInRange(searchRange, EndOfLinePreference.LF);
const result: FindMatch[] = [];
let counter = 0;
let m: RegExpExecArray;
searcher.reset(0);
while ((m = searcher.next(text))) {
result[counter++] = createFindMatch(this._getMultilineMatchRange(model, deltaOffset, text, m.index, m[0]), m, captureMatches);
if (counter >= limitResultCount) {
return result;
}
}
return result;
}
示例4: _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
};
}
示例5: _doFindMatchesMultiline
private static _doFindMatchesMultiline(model: TextModel, searchRange: Range, searchRegex: RegExp, captureMatches: boolean, limitResultCount: number): FindMatch[] {
const deltaOffset = model.getOffsetAt(searchRange.getStartPosition());
const text = model.getValueInRange(searchRange);
const result: FindMatch[] = [];
let prevStartOffset = 0;
let prevEndOffset = 0;
let counter = 0;
let m: RegExpExecArray;
while ((m = searchRegex.exec(text))) {
const startOffset = deltaOffset + m.index;
const endOffset = startOffset + m[0].length;
if (prevStartOffset === startOffset && prevEndOffset === endOffset) {
// Exit early if the regex matches the same range
return result;
}
const startPosition = model.getPositionAt(startOffset);
const endPosition = model.getPositionAt(endOffset);
result[counter++] = createFindMatch(
new Range(startPosition.lineNumber, startPosition.column, endPosition.lineNumber, endPosition.column),
m,
captureMatches
);
if (counter >= limitResultCount) {
return result;
}
prevStartOffset = startOffset;
prevEndOffset = endOffset;
}
return result;
}
示例6: _doFindMatchesMultiline
private static _doFindMatchesMultiline(model: TextModel, searchRange: Range, searchRegex: RegExp, captureMatches: boolean, limitResultCount: number): FindMatch[] {
const deltaOffset = model.getOffsetAt(searchRange.getStartPosition());
// We always execute multiline search over the lines joined with \n
// This makes it that \n will match the EOL for both CRLF and LF models
// We compensate for offset errors in `_getMultilineMatchRange`
const text = model.getValueInRange(searchRange, EndOfLinePreference.LF);
const result: FindMatch[] = [];
let prevStartOffset = 0;
let prevEndOffset = 0;
let counter = 0;
let m: RegExpExecArray;
while ((m = searchRegex.exec(text))) {
const startOffset = deltaOffset + m.index;
const endOffset = startOffset + m[0].length;
if (prevStartOffset === startOffset && prevEndOffset === endOffset) {
// Exit early if the regex matches the same range
return result;
}
result[counter++] = createFindMatch(
this._getMultilineMatchRange(model, deltaOffset, text, m.index, m[0]),
m,
captureMatches
);
if (counter >= limitResultCount) {
return result;
}
prevStartOffset = startOffset;
prevEndOffset = endOffset;
}
return result;
}
示例7: _enter
private static _enter(config: CursorConfiguration, model: ITextModel, keepPosition: boolean, range: Range): ICommand {
if (!model.isCheapToTokenize(range.getStartPosition().lineNumber)) {
let lineText = model.getLineContent(range.startLineNumber);
let indentation = strings.getLeadingWhitespace(lineText).substring(0, range.startColumn - 1);
return TypeOperations._typeCommand(range, '\n' + config.normalizeIndentation(indentation), keepPosition);
}
let r = LanguageConfigurationRegistry.getEnterAction(model, range);
if (r) {
let enterAction = r.enterAction;
let indentation = r.indentation;
if (enterAction.indentAction === IndentAction.None) {
// Nothing special
return TypeOperations._typeCommand(range, '\n' + config.normalizeIndentation(indentation + enterAction.appendText), keepPosition);
} else if (enterAction.indentAction === IndentAction.Indent) {
// Indent once
return TypeOperations._typeCommand(range, '\n' + config.normalizeIndentation(indentation + enterAction.appendText), keepPosition);
} else if (enterAction.indentAction === IndentAction.IndentOutdent) {
// Ultra special
let normalIndent = config.normalizeIndentation(indentation);
let increasedIndent = config.normalizeIndentation(indentation + enterAction.appendText);
let typeText = '\n' + increasedIndent + '\n' + normalIndent;
if (keepPosition) {
return new ReplaceCommandWithoutChangingPosition(range, typeText, true);
} else {
return new ReplaceCommandWithOffsetCursorState(range, typeText, -1, increasedIndent.length - normalIndent.length, true);
}
} else if (enterAction.indentAction === IndentAction.Outdent) {
let actualIndentation = TypeOperations.unshiftIndent(config, indentation);
return TypeOperations._typeCommand(range, '\n' + config.normalizeIndentation(actualIndentation + enterAction.appendText), keepPosition);
}
}
// no enter rules applied, we should check indentation rules then.
if (!config.autoIndent) {
// Nothing special
let lineText = model.getLineContent(range.startLineNumber);
let indentation = strings.getLeadingWhitespace(lineText).substring(0, range.startColumn - 1);
return TypeOperations._typeCommand(range, '\n' + config.normalizeIndentation(indentation), keepPosition);
}
let ir = LanguageConfigurationRegistry.getIndentForEnter(model, range, {
unshiftIndent: (indent) => {
return TypeOperations.unshiftIndent(config, indent);
},
shiftIndent: (indent) => {
return TypeOperations.shiftIndent(config, indent);
},
normalizeIndentation: (indent) => {
return config.normalizeIndentation(indent);
}
}, config.autoIndent);
let lineText = model.getLineContent(range.startLineNumber);
let indentation = strings.getLeadingWhitespace(lineText).substring(0, range.startColumn - 1);
if (ir) {
let oldEndViewColumn = CursorColumns.visibleColumnFromColumn2(config, model, range.getEndPosition());
let oldEndColumn = range.endColumn;
let beforeText = '\n';
if (indentation !== config.normalizeIndentation(ir.beforeEnter)) {
beforeText = config.normalizeIndentation(ir.beforeEnter) + lineText.substring(indentation.length, range.startColumn - 1) + '\n';
range = new Range(range.startLineNumber, 1, range.endLineNumber, range.endColumn);
}
let newLineContent = model.getLineContent(range.endLineNumber);
let firstNonWhitespace = strings.firstNonWhitespaceIndex(newLineContent);
if (firstNonWhitespace >= 0) {
range = range.setEndPosition(range.endLineNumber, Math.max(range.endColumn, firstNonWhitespace + 1));
} else {
range = range.setEndPosition(range.endLineNumber, model.getLineMaxColumn(range.endLineNumber));
}
if (keepPosition) {
return new ReplaceCommandWithoutChangingPosition(range, beforeText + config.normalizeIndentation(ir.afterEnter), true);
} else {
let offset = 0;
if (oldEndColumn <= firstNonWhitespace + 1) {
if (!config.insertSpaces) {
oldEndViewColumn = Math.ceil(oldEndViewColumn / config.tabSize);
}
offset = Math.min(oldEndViewColumn + 1 - config.normalizeIndentation(ir.afterEnter).length - 1, 0);
}
return new ReplaceCommandWithOffsetCursorState(range, beforeText + config.normalizeIndentation(ir.afterEnter), 0, offset, true);
}
} else {
return TypeOperations._typeCommand(range, '\n' + config.normalizeIndentation(indentation), keepPosition);
}
}