本文整理汇总了TypeScript中vs/editor/common/core/range.Range类的典型用法代码示例。如果您正苦于以下问题:TypeScript Range类的具体用法?TypeScript Range怎么用?TypeScript Range使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Range类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: _enter
private static _enter(config: CursorConfiguration, model: ITokenizedModel, keepPosition: boolean, range: Range): ICommand {
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.
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);
}
}
示例2:
ops.sort((o1, o2) => {
return Range.compareRangesUsingStarts(o1.range, o2.range);
});
示例3: symbolEntry
private symbolEntry(name: string, type: string, description: string, range: IRange, highlights: IHighlight[], editor: ICodeEditor, decorator: IDecorator): SymbolEntry {
return new SymbolEntry(name, type, description, Range.lift(range), highlights, editor, decorator);
}
示例4: toQuickOpenEntries
private toQuickOpenEntries(editor: ICommonCodeEditor, flattened: SymbolInformation[], searchValue: string): SymbolEntry[] {
const controller = this.getController(editor);
let results: SymbolEntry[] = [];
// Convert to Entries
let normalizedSearchValue = searchValue;
if (searchValue.indexOf(SCOPE_PREFIX) === 0) {
normalizedSearchValue = normalizedSearchValue.substr(SCOPE_PREFIX.length);
}
for (let i = 0; i < flattened.length; i++) {
let element = flattened[i];
let label = strings.trim(element.name);
// Check for meatch
let highlights = matchesFuzzy(normalizedSearchValue, label);
if (highlights) {
// Show parent scope as description
let description: string = null;
if (element.containerName) {
description = element.containerName;
}
// Add
results.push(new SymbolEntry(label, symbolKindToCssClass(element.kind), description, Range.lift(element.location.range), highlights, editor, controller));
}
}
// Sort properly if actually searching
if (searchValue) {
if (searchValue.indexOf(SCOPE_PREFIX) === 0) {
results = results.sort(this.sortScoped.bind(this, searchValue.toLowerCase()));
} else {
results = results.sort(this.sortNormal.bind(this, searchValue.toLowerCase()));
}
}
// Mark all type groups
if (results.length > 0 && searchValue.indexOf(SCOPE_PREFIX) === 0) {
let currentType: string = null;
let currentResult: SymbolEntry = null;
let typeCounter = 0;
for (let i = 0; i < results.length; i++) {
let result = results[i];
// Found new type
if (currentType !== result.getType()) {
// Update previous result with count
if (currentResult) {
currentResult.setGroupLabel(this.typeToLabel(currentType, typeCounter));
}
currentType = result.getType();
currentResult = result;
typeCounter = 1;
result.setShowBorder(i > 0);
}
// Existing type, keep counting
else {
typeCounter++;
}
}
// Update previous result with count
if (currentResult) {
currentResult.setGroupLabel(this.typeToLabel(currentType, typeCounter));
}
}
// Mark first entry as outline
else if (results.length > 0) {
results[0].setGroupLabel(nls.localize('symbols', "symbols ({0})", results.length));
}
return results;
}
示例5: _deltaDecorationsImpl
private _deltaDecorationsImpl(decorationsTracker: DecorationsTracker, ownerId: number, oldDecorationsIds: string[], newDecorations: ModelDeltaDecoration[]): string[] {
if (oldDecorationsIds.length === 0) {
// Nothing to remove
return this._addDecorationsImpl(decorationsTracker, ownerId, newDecorations);
}
if (newDecorations.length === 0) {
// Nothing to add
this._removeDecorationsImpl(decorationsTracker, oldDecorationsIds);
return [];
}
let oldDecorations = this._resolveOldDecorations(oldDecorationsIds);
oldDecorations.sort((a, b) => Range.compareRangesUsingStarts(a.range, b.range));
newDecorations.sort((a, b) => Range.compareRangesUsingStarts(a.range, b.range));
let result: string[] = [],
oldDecorationsIndex = 0,
oldDecorationsLength = oldDecorations.length,
newDecorationsIndex = 0,
newDecorationsLength = newDecorations.length,
decorationsToAdd: ModelDeltaDecoration[] = [],
decorationsToRemove: string[] = [];
while (oldDecorationsIndex < oldDecorationsLength && newDecorationsIndex < newDecorationsLength) {
let oldDecoration = oldDecorations[oldDecorationsIndex];
let newDecoration = newDecorations[newDecorationsIndex];
let comparison = Range.compareRangesUsingStarts(oldDecoration.range, newDecoration.range);
if (comparison < 0) {
// `oldDecoration` is before `newDecoration` => remove `oldDecoration`
decorationsToRemove.push(oldDecoration.id);
oldDecorationsIndex++;
continue;
}
if (comparison > 0) {
// `newDecoration` is before `oldDecoration` => add `newDecoration`
decorationsToAdd.push(newDecoration);
newDecorationsIndex++;
continue;
}
// The ranges of `oldDecoration` and `newDecoration` are equal
if (!oldDecoration.options.equals(newDecoration.options)) {
// The options do not match => remove `oldDecoration`
decorationsToRemove.push(oldDecoration.id);
oldDecorationsIndex++;
continue;
}
// Bingo! We can reuse `oldDecoration` for `newDecoration`
result[newDecoration.index] = oldDecoration.id;
oldDecorationsIndex++;
newDecorationsIndex++;
}
while (oldDecorationsIndex < oldDecorationsLength) {
// No more new decorations => remove decoration at `oldDecorationsIndex`
decorationsToRemove.push(oldDecorations[oldDecorationsIndex].id);
oldDecorationsIndex++;
}
while (newDecorationsIndex < newDecorationsLength) {
// No more old decorations => add decoration at `newDecorationsIndex`
decorationsToAdd.push(newDecorations[newDecorationsIndex]);
newDecorationsIndex++;
}
// Remove `decorationsToRemove`
if (decorationsToRemove.length > 0) {
this._removeDecorationsImpl(decorationsTracker, decorationsToRemove);
}
// Add `decorationsToAdd`
if (decorationsToAdd.length > 0) {
let newIds = this._addDecorationsImpl(decorationsTracker, ownerId, decorationsToAdd);
for (let i = 0, len = decorationsToAdd.length; i < len; i++) {
result[decorationsToAdd[i].index] = newIds[i];
}
}
return result;
}
示例6: cut
public static cut(config: CursorConfiguration, model: ICursorSimpleModel, selections: Selection[]): EditOperationResult {
let commands: (ICommand | null)[] = [];
for (let i = 0, len = selections.length; i < len; i++) {
const selection = selections[i];
if (selection.isEmpty()) {
if (config.emptySelectionClipboard) {
// This is a full line cut
let position = selection.getPosition();
let startLineNumber: number,
startColumn: number,
endLineNumber: number,
endColumn: number;
if (position.lineNumber < model.getLineCount()) {
// Cutting a line in the middle of the model
startLineNumber = position.lineNumber;
startColumn = 1;
endLineNumber = position.lineNumber + 1;
endColumn = 1;
} else if (position.lineNumber > 1) {
// Cutting the last line & there are more than 1 lines in the model
startLineNumber = position.lineNumber - 1;
startColumn = model.getLineMaxColumn(position.lineNumber - 1);
endLineNumber = position.lineNumber;
endColumn = model.getLineMaxColumn(position.lineNumber);
} else {
// Cutting the single line that the model contains
startLineNumber = position.lineNumber;
startColumn = 1;
endLineNumber = position.lineNumber;
endColumn = model.getLineMaxColumn(position.lineNumber);
}
let deleteSelection = new Range(
startLineNumber,
startColumn,
endLineNumber,
endColumn
);
if (!deleteSelection.isEmpty()) {
commands[i] = new ReplaceCommand(deleteSelection, '');
} else {
commands[i] = null;
}
} else {
// Cannot cut empty selection
commands[i] = null;
}
} else {
commands[i] = new ReplaceCommand(selection, '');
}
}
return new EditOperationResult(EditOperationType.Other, commands, {
shouldPushStackElementBefore: true,
shouldPushStackElementAfter: true
});
}
示例7:
operations = operations.sort((a, b) => -Range.compareRangesUsingEnds(a.range, b.range));
示例8:
editor.executeEdits('formatEditsCommand', edits.map(edit => EditOperation.replaceMove(Range.lift(edit.range), edit.text)));
示例9: compareEntriesUsingStart
function compareEntriesUsingStart(a: DocumentSymbol, b: DocumentSymbol): number {
return Range.compareRangesUsingStarts(a.range, b.range);
}
示例10: hasSelection
public hasSelection(): boolean {
return (!this.selection.isEmpty() || !this.selectionStart.isEmpty());
}