Rename custom Range class to Cursor

Refs #4585
This commit is contained in:
Jason Fields 2021-05-29 21:09:07 -04:00
parent 07b542874f
commit fe6a154f78
14 changed files with 137 additions and 142 deletions

View File

@ -1,5 +1,5 @@
import { Position } from 'vscode';
import { Range } from '../common/motion/range';
import { Cursor } from '../common/motion/cursor';
import { Notation } from '../configuration/notation';
import { isTextTransformation } from '../transformations/transformations';
import { configuration } from './../configuration/configuration';
@ -230,10 +230,10 @@ export abstract class BaseCommand extends BaseAction {
return;
}
const resultingCursors: Range[] = [];
const resultingCursors: Cursor[] = [];
const cursorsToIterateOver = vimState.cursors
.map((x) => new Range(x.start, x.stop))
.map((x) => new Cursor(x.start, x.stop))
.sort((a, b) =>
a.start.line > b.start.line ||
(a.start.line === b.start.line && a.start.character > b.start.character)
@ -252,7 +252,7 @@ export abstract class BaseCommand extends BaseAction {
await this.exec(stop, vimState);
}
resultingCursors.push(new Range(vimState.cursorStartPosition, vimState.cursorStopPosition));
resultingCursors.push(new Cursor(vimState.cursorStartPosition, vimState.cursorStopPosition));
for (const transformation of vimState.recordedState.transformer.transformations) {
if (isTextTransformation(transformation) && transformation.cursorIndex === undefined) {

View File

@ -10,7 +10,7 @@ import { OnlyCommand } from './../../cmd_line/commands/only';
import { QuitCommand } from './../../cmd_line/commands/quit';
import { Tab, TabCommand } from './../../cmd_line/commands/tab';
import { PositionDiff, earlierOf, laterOf, sorted } from './../../common/motion/position';
import { Range } from './../../common/motion/range';
import { Cursor } from '../../common/motion/cursor';
import { NumericString } from './../../common/number/numericString';
import { configuration } from './../../configuration/configuration';
import {
@ -1155,7 +1155,7 @@ export class CommandUndo extends BaseCommand {
if (newPositions === undefined) {
StatusBar.setText(vimState, 'Already at oldest change');
} else {
vimState.cursors = newPositions.map((x) => new Range(x, x));
vimState.cursors = newPositions.map((x) => new Cursor(x, x));
}
vimState.alteredHistory = true;
@ -1175,7 +1175,7 @@ class CommandUndoOnLine extends BaseCommand {
const newPositions = await vimState.historyTracker.goBackHistoryStepsOnLine();
if (newPositions !== undefined) {
vimState.cursors = newPositions.map((x) => new Range(x, x));
vimState.cursors = newPositions.map((x) => new Cursor(x, x));
}
vimState.alteredHistory = true;
@ -1196,7 +1196,7 @@ class CommandRedo extends BaseCommand {
if (newPositions === undefined) {
StatusBar.setText(vimState, 'Already at newest change');
} else {
vimState.cursors = newPositions.map((x) => new Range(x, x));
vimState.cursors = newPositions.map((x) => new Cursor(x, x));
}
vimState.alteredHistory = true;
@ -1609,7 +1609,7 @@ class CommandInsertNewLineAbove extends BaseCommand {
vimState.cursors[0].start.line + i,
vimState.cursors[0].start.character
);
vimState.cursors.push(new Range(newPos, newPos));
vimState.cursors.push(new Cursor(newPos, newPos));
}
vimState.cursors = vimState.cursors.reverse();
vimState.isFakeMultiCursor = true;
@ -1638,7 +1638,7 @@ class CommandInsertNewLineBefore extends BaseCommand {
vimState.cursorStartPosition.line - i,
vimState.cursorStartPosition.character
);
vimState.cursors.push(new Range(newPos, newPos));
vimState.cursors.push(new Cursor(newPos, newPos));
// Ahhhhhh. We have to manually set cursor position here as we need text
// transformations AND to set multiple cursors.
@ -2115,7 +2115,7 @@ class ActionJoin extends BaseCommand {
public async execCount(position: Position, vimState: VimState): Promise<void> {
const cursorsToIterateOver = vimState.cursors
.map((x) => new Range(x.start, x.stop))
.map((x) => new Cursor(x.start, x.stop))
.sort((a, b) =>
a.start.line > b.start.line ||
(a.start.line === b.start.line && a.start.character > b.start.character)
@ -2123,7 +2123,7 @@ class ActionJoin extends BaseCommand {
: -1
);
const resultingCursors: Range[] = [];
const resultingCursors: Cursor[] = [];
for (const [idx, { start, stop }] of cursorsToIterateOver.entries()) {
this.multicursorIndex = idx;
@ -2132,7 +2132,7 @@ class ActionJoin extends BaseCommand {
await this.execJoinLines(start, stop, vimState, vimState.recordedState.count || 1);
resultingCursors.push(new Range(vimState.cursorStartPosition, vimState.cursorStopPosition));
resultingCursors.push(new Cursor(vimState.cursorStartPosition, vimState.cursorStopPosition));
for (const transformation of vimState.recordedState.transformer.transformations) {
if (isTextTransformation(transformation) && transformation.cursorIndex === undefined) {
@ -2409,7 +2409,7 @@ class ActionReplaceCharacterVisualBlock extends BaseCommand {
vimState.cursorStopPosition,
vimState.cursorStartPosition
);
vimState.cursors = [new Range(topLeft, topLeft)];
vimState.cursors = [new Cursor(topLeft, topLeft)];
await vimState.setCurrentMode(Mode.Normal);
}
}
@ -2444,7 +2444,7 @@ class ActionDeleteVisualBlock extends BaseCommand {
vimState.cursorStartPosition
);
vimState.cursors = [new Range(topLeft, topLeft)];
vimState.cursors = [new Cursor(topLeft, topLeft)];
await vimState.setCurrentMode(Mode.Normal);
}
}
@ -2472,7 +2472,7 @@ class ActionShiftDVisualBlock extends BaseCommand {
vimState.cursorStartPosition
);
vimState.cursors = [new Range(topLeft, topLeft)];
vimState.cursors = [new Cursor(topLeft, topLeft)];
await vimState.setCurrentMode(Mode.Normal);
}
}
@ -2494,7 +2494,7 @@ class ActionGoToInsertVisualBlockMode extends BaseCommand {
if (line === '' && start.character !== 0) {
continue;
}
vimState.cursors.push(new Range(start, start));
vimState.cursors.push(new Cursor(start, start));
}
vimState.cursors = vimState.cursors.slice(1);
}
@ -2522,7 +2522,7 @@ class ActionChangeInVisualBlockMode extends BaseCommand {
vimState.isFakeMultiCursor = true;
for (const { start } of TextEditor.iterateLinesInBlock(vimState)) {
vimState.cursors.push(new Range(start, start));
vimState.cursors.push(new Cursor(start, start));
}
vimState.cursors = vimState.cursors.slice(1);
}
@ -2537,7 +2537,7 @@ class ActionChangeToEOLInVisualBlockMode extends BaseCommand {
}
public async exec(position: Position, vimState: VimState): Promise<void> {
const cursors: Range[] = [];
const cursors: Cursor[] = [];
for (const cursor of vimState.cursors) {
for (const { start, end } of TextEditor.iterateLinesInBlock(vimState, cursor)) {
vimState.recordedState.transformer.addTransformation({
@ -2545,7 +2545,7 @@ class ActionChangeToEOLInVisualBlockMode extends BaseCommand {
range: new vscode.Range(start, start.getLineEnd()),
collapseRange: true,
});
cursors.push(new Range(end, end));
cursors.push(new Cursor(end, end));
}
}
vimState.cursors = cursors;
@ -2565,15 +2565,15 @@ abstract class ActionGoToInsertVisualLineModeCommand extends BaseCommand {
line: vscode.TextLine,
selectionStart: Position,
selectionEnd: Position
): Range;
): Cursor;
public async exec(position: Position, vimState: VimState): Promise<void> {
await vimState.setCurrentMode(Mode.Insert);
vimState.isMultiCursor = true;
vimState.isFakeMultiCursor = true;
const resultingCursors: Range[] = [];
const cursorsOnBlankLines: Range[] = [];
const resultingCursors: Cursor[] = [];
const cursorsOnBlankLines: Cursor[] = [];
for (const selection of vimState.editor.selections) {
const { start, end } = selection;
@ -2602,12 +2602,12 @@ class ActionGoToInsertVisualLineMode extends ActionGoToInsertVisualLineModeComma
modes = [Mode.VisualLine];
keys = ['I'];
getCursorRangeForLine(line: vscode.TextLine): Range {
getCursorRangeForLine(line: vscode.TextLine): Cursor {
const startCharacterPosition = new Position(
line.lineNumber,
line.firstNonWhitespaceCharacterIndex
);
return new Range(startCharacterPosition, startCharacterPosition);
return new Cursor(startCharacterPosition, startCharacterPosition);
}
}
@ -2616,9 +2616,9 @@ class ActionGoToInsertVisualLineModeAppend extends ActionGoToInsertVisualLineMod
modes = [Mode.VisualLine];
keys = ['A'];
getCursorRangeForLine(line: vscode.TextLine): Range {
getCursorRangeForLine(line: vscode.TextLine): Cursor {
const endCharacterPosition = new Position(line.lineNumber, line.range.end.character);
return new Range(endCharacterPosition, endCharacterPosition);
return new Cursor(endCharacterPosition, endCharacterPosition);
}
}
@ -2631,12 +2631,12 @@ class ActionGoToInsertVisualMode extends ActionGoToInsertVisualLineModeCommand {
line: vscode.TextLine,
selectionStart: Position,
selectionEnd: Position
): Range {
): Cursor {
const startCharacterPosition =
line.lineNumber === selectionStart.line
? selectionStart
: new Position(line.lineNumber, line.firstNonWhitespaceCharacterIndex);
return new Range(startCharacterPosition, startCharacterPosition);
return new Cursor(startCharacterPosition, startCharacterPosition);
}
}
@ -2649,12 +2649,12 @@ class ActionGoToInsertVisualModeAppend extends ActionGoToInsertVisualLineModeCom
line: vscode.TextLine,
selectionStart: Position,
selectionEnd: Position
): Range {
): Cursor {
const endCharacterPosition =
line.lineNumber === selectionEnd.line
? selectionEnd
: new Position(line.lineNumber, line.range.end.character);
return new Range(endCharacterPosition, endCharacterPosition);
return new Cursor(endCharacterPosition, endCharacterPosition);
}
}
@ -2667,7 +2667,7 @@ class ActionGoToInsertVisualBlockModeAppend extends BaseCommand {
}
public async exec(position: Position, vimState: VimState): Promise<void> {
const newCursors: Range[] = [];
const newCursors: Cursor[] = [];
for (const cursor of vimState.cursors) {
const [start, end] = sorted(cursor.start, cursor.stop);
for (let lineNum = start.line; lineNum <= end.line; lineNum++) {
@ -2685,7 +2685,7 @@ class ActionGoToInsertVisualBlockModeAppend extends BaseCommand {
);
}
const newCursor = new Position(lineNum, insertionColumn);
newCursors.push(new Range(newCursor, newCursor));
newCursors.push(new Cursor(newCursor, newCursor));
}
}
@ -2913,31 +2913,31 @@ abstract class IncrementDecrementNumberAction extends BaseCommand {
/**
* @returns a list of Ranges in which to search for numbers
*/
private getSearchRanges(vimState: VimState): Range[] {
const ranges: Range[] = [];
private getSearchRanges(vimState: VimState): Cursor[] {
const ranges: Cursor[] = [];
const [start, stop] = sorted(vimState.cursorStartPosition, vimState.cursorStopPosition);
switch (vimState.currentMode) {
case Mode.Normal: {
ranges.push(
new Range(vimState.cursorStopPosition, vimState.cursorStopPosition.getLineEnd())
new Cursor(vimState.cursorStopPosition, vimState.cursorStopPosition.getLineEnd())
);
break;
}
case Mode.Visual: {
ranges.push(new Range(start, start.getLineEnd()));
ranges.push(new Cursor(start, start.getLineEnd()));
for (let line = start.line + 1; line < stop.line; line++) {
const lineStart = new Position(line, 0);
ranges.push(new Range(lineStart, lineStart.getLineEnd()));
ranges.push(new Cursor(lineStart, lineStart.getLineEnd()));
}
ranges.push(new Range(stop.getLineBegin(), stop));
ranges.push(new Cursor(stop.getLineBegin(), stop));
break;
}
case Mode.VisualLine: {
for (let line = start.line; line <= stop.line; line++) {
const lineStart = new Position(line, 0);
ranges.push(new Range(lineStart, lineStart.getLineEnd()));
ranges.push(new Cursor(lineStart, lineStart.getLineEnd()));
}
break;
}
@ -2947,7 +2947,7 @@ abstract class IncrementDecrementNumberAction extends BaseCommand {
const bottomRight = visualBlockGetBottomRightPosition(start, stop);
for (let line = topLeft.line; line <= bottomRight.line; line++) {
ranges.push(
new Range(
new Cursor(
new Position(line, topLeft.character),
new Position(line, bottomRight.character)
)

View File

@ -11,7 +11,7 @@ import { reportLinesChanged } from '../../util/statusBarTextUtils';
import { BaseCommand, RegisterAction } from '../base';
import { StatusBar } from '../../statusBar';
import { VimError, ErrorCode } from '../../error';
import { Range } from '../../common/motion/range';
import { Cursor } from '../../common/motion/cursor';
import { Transformation } from '../../transformations/transformations';
function firstNonBlankChar(text: string): number {
@ -276,7 +276,7 @@ abstract class BasePutCommand extends BaseCommand {
protected abstract getReplaceRange(
mode: Mode,
cursor: Range,
cursor: Cursor,
registerMode: RegisterMode
): vscode.Range;
@ -306,7 +306,7 @@ class PutCommand extends BasePutCommand {
return register.registerMode;
}
protected getReplaceRange(mode: Mode, cursor: Range, registerMode: RegisterMode): vscode.Range {
protected getReplaceRange(mode: Mode, cursor: Cursor, registerMode: RegisterMode): vscode.Range {
if (mode === Mode.Normal) {
let pos: Position;
if (registerMode === RegisterMode.CharacterWise || registerMode === RegisterMode.BlockWise) {
@ -394,7 +394,7 @@ class PutBeforeCommand extends PutCommand {
return super.adjustLinewiseRegisterText(mode, text);
}
protected getReplaceRange(mode: Mode, cursor: Range, registerMode: RegisterMode): vscode.Range {
protected getReplaceRange(mode: Mode, cursor: Cursor, registerMode: RegisterMode): vscode.Range {
if (mode === Mode.Normal) {
if (registerMode === RegisterMode.CharacterWise || registerMode === RegisterMode.BlockWise) {
const pos = cursor.stop;
@ -539,7 +539,7 @@ function ExCommand<TBase extends new (...args: any[]) => PutCommand>(Base: TBase
return RegisterMode.LineWise;
}
protected getReplaceRange(mode: Mode, cursor: Range, registerMode: RegisterMode): vscode.Range {
protected getReplaceRange(mode: Mode, cursor: Cursor, registerMode: RegisterMode): vscode.Range {
const line = this.insertLine ?? laterOf(cursor.start, cursor.stop).line;
const pos = this.putBefore() ? new Position(line, 0) : new Position(line, 0).getLineEnd();
return new vscode.Range(pos, pos);

View File

@ -4,7 +4,7 @@ import * as node from '../node';
import { VimState } from '../../state/vimState';
import { globalState } from '../../state/globalState';
import { Jump } from '../../jumps/jump';
import { Range } from '../../common/motion/range';
import { Cursor } from '../../common/motion/cursor';
class JumpPickItem implements QuickPickItem {
jump: Jump;
@ -37,7 +37,7 @@ export class JumpsCommand extends node.CommandBase {
});
if (item && item.jump.document !== undefined) {
window.showTextDocument(item.jump.document);
vimState.cursors = [new Range(item.jump.position, item.jump.position)];
vimState.cursors = [new Cursor(item.jump.position, item.jump.position)];
}
} else {
window.showInformationMessage('No jumps available');

View File

@ -3,7 +3,7 @@ import { window, QuickPickItem } from 'vscode';
import * as node from '../node';
import { VimState } from '../../state/vimState';
import { IMark } from '../../history/historyTracker';
import { Range } from '../../common/motion/range';
import { Cursor } from '../../common/motion/cursor';
import { StatusBar } from '../../statusBar';
import { ErrorCode, VimError } from '../../error';
@ -45,7 +45,7 @@ export class MarksCommand extends node.CommandBase {
canPickMany: false,
});
if (item) {
vimState.cursors = [new Range(item.mark.position, item.mark.position)];
vimState.cursors = [new Cursor(item.mark.position, item.mark.position)];
}
} else {
window.showInformationMessage('No marks set');

View File

@ -0,0 +1,44 @@
import { Position, Selection, TextEditor } from 'vscode';
export class Cursor {
public readonly start: Position;
public readonly stop: Position;
constructor(start: Position, stop: Position) {
this.start = start;
this.stop = stop;
}
public isValid(textEditor: TextEditor) {
return this.start.isValid(textEditor) && this.stop.isValid(textEditor);
}
/**
* Create a Cursor from a VSCode selection.
*/
public static FromVSCodeSelection(sel: Selection): Cursor {
return new Cursor(sel.start, sel.end);
}
public equals(other: Cursor): boolean {
return this.start.isEqual(other.start) && this.stop.isEqual(other.stop);
}
/**
* Returns a new Cursor which is the same as this Cursor, but with the provided stop value.
*/
public withNewStop(stop: Position): Cursor {
return new Cursor(this.start, stop);
}
/**
* Returns a new Cursor which is the same as this Cursor, but with the provided start value.
*/
public withNewStart(start: Position): Cursor {
return new Cursor(start, this.stop);
}
public toString(): string {
return `[ ${this.start.toString()} | ${this.stop.toString()}]`;
}
}

View File

@ -1,49 +0,0 @@
import * as vscode from 'vscode';
import { Position } from 'vscode';
export class Range {
public readonly start: Position;
public readonly stop: Position;
constructor(start: Position, stop: Position) {
this.start = start;
this.stop = stop;
}
public isValid(textEditor: vscode.TextEditor) {
return this.start.isValid(textEditor) && this.stop.isValid(textEditor);
}
/**
* Create a range from a VSCode selection.
*/
public static FromVSCodeSelection(sel: vscode.Selection): Range {
return new Range(sel.start, sel.end);
}
public equals(other: Range): boolean {
return this.start.isEqual(other.start) && this.stop.isEqual(other.stop);
}
/**
* Returns a new Range which is the same as this Range, but with the provided stop value.
*/
public withNewStop(stop: Position): Range {
return new Range(this.start, stop);
}
/**
* Returns a new Range which is the same as this Range, but with the provided start value.
*/
public withNewStart(start: Position): Range {
return new Range(start, this.stop);
}
public toString(): string {
return `[ ${this.start.toString()} | ${this.stop.toString()}]`;
}
public overlaps(other: Range): boolean {
return this.start.isBefore(other.stop) && other.start.isBefore(this.stop);
}
}

View File

@ -14,7 +14,7 @@ import { Logger } from '../util/logger';
import { Mode, VSCodeVimCursorType, isVisualMode, getCursorStyle, isStatusBarMode } from './mode';
import { PairMatcher } from './../common/matching/matcher';
import { laterOf } from './../common/motion/position';
import { Range } from './../common/motion/range';
import { Cursor } from '../common/motion/cursor';
import { IBaseAction, RecordedState } from './../state/recordedState';
import { Register, RegisterMode } from './../register/register';
import { Remappers } from '../configuration/remapper';
@ -113,7 +113,7 @@ export class ModeHandler implements vscode.Disposable, IModeHandler {
}
this.vimState.cursors = selections.map(({ active, anchor }) =>
active.isBefore(anchor) ? new Range(anchor.getLeft(), active) : new Range(anchor, active)
active.isBefore(anchor) ? new Cursor(anchor.getLeft(), active) : new Cursor(anchor, active)
);
}
}
@ -179,7 +179,7 @@ export class ModeHandler implements vscode.Disposable, IModeHandler {
// Number of selections changed, make sure we know about all of them still
this.vimState.cursors = e.textEditor.selections.map(
(sel) =>
new Range(
new Cursor(
// Adjust the cursor positions because cursors & selections don't match exactly
sel.anchor.isAfter(sel.active) ? sel.anchor.getLeft() : sel.anchor,
sel.active
@ -713,7 +713,7 @@ export class ModeHandler implements vscode.Disposable, IModeHandler {
// It's not 100% clear to me that this is the correct place to do this, but it should solve a lot of issues
this.vimState.cursors = this.vimState.cursors.map(
(c) =>
new Range(
new Cursor(
this.vimState.document.validatePosition(c.start),
this.vimState.document.validatePosition(c.stop)
)
@ -867,7 +867,7 @@ export class ModeHandler implements vscode.Disposable, IModeHandler {
if (this.currentMode === Mode.Normal) {
this.vimState.cursors = this.vimState.cursors.map(
(cursor) => new Range(cursor.stop, cursor.stop)
(cursor) => new Cursor(cursor.stop, cursor.stop)
);
}
@ -876,7 +876,7 @@ export class ModeHandler implements vscode.Disposable, IModeHandler {
!this.vimState.document.isClosed &&
this.vimState.editor === vscode.window.activeTextEditor
) {
this.vimState.cursors = this.vimState.cursors.map((cursor: Range) => {
this.vimState.cursors = this.vimState.cursors.map((cursor: Cursor) => {
// adjust start/stop
const documentEndPosition = TextEditor.getDocumentEnd(this.vimState.document);
const documentLineCount = this.vimState.document.lineCount;
@ -958,7 +958,7 @@ export class ModeHandler implements vscode.Disposable, IModeHandler {
// We also need to update the specific cursor, in case the cursor position was modified inside
// the handling functions (e.g. 'it')
this.vimState.cursors[i] = new Range(
this.vimState.cursors[i] = new Cursor(
this.vimState.cursorStartPosition,
this.vimState.cursorStopPosition
);
@ -981,7 +981,7 @@ export class ModeHandler implements vscode.Disposable, IModeHandler {
if (result.removed) {
cursorsToRemove.push(i);
} else {
this.vimState.cursors[i] = new Range(result.start, result.stop);
this.vimState.cursors[i] = new Cursor(result.start, result.stop);
}
if (result.registerMode) {
@ -1029,7 +1029,7 @@ export class ModeHandler implements vscode.Disposable, IModeHandler {
const startingMode = this.vimState.currentMode;
const startingRegisterMode = this.vimState.currentRegisterMode;
const resultingCursors: Range[] = [];
const resultingCursors: Cursor[] = [];
for (let [i, { start, stop }] of this.vimState.cursors.entries()) {
operator.multicursorIndex = i;
@ -1067,12 +1067,12 @@ export class ModeHandler implements vscode.Disposable, IModeHandler {
}
}
const resultingRange = new Range(
const resultingCursor = new Cursor(
this.vimState.cursorStartPosition,
this.vimState.cursorStopPosition
);
resultingCursors.push(resultingRange);
resultingCursors.push(resultingCursor);
}
if (this.vimState.recordedState.transformer.transformations.length > 0) {
@ -1336,7 +1336,7 @@ export class ModeHandler implements vscode.Disposable, IModeHandler {
const isLastCursorTracked =
this.vimState.recordedState.getLastActionRun() instanceof ActionOverrideCmdD;
let cursorToTrack: Range;
let cursorToTrack: Cursor;
if (isLastCursorTracked) {
cursorToTrack = this.vimState.cursors[this.vimState.cursors.length - 1];
} else {

View File

@ -7,7 +7,7 @@ import { EditorIdentity } from './../editorIdentity';
import { HistoryTracker } from './../history/historyTracker';
import { Logger } from '../util/logger';
import { Mode } from '../mode/mode';
import { Range } from './../common/motion/range';
import { Cursor } from '../common/motion/cursor';
import { RecordedState } from './recordedState';
import { RegisterMode } from './../register/register';
import { ReplaceState } from './../state/replaceState';
@ -159,18 +159,18 @@ export class VimState implements vscode.Disposable {
/**
* The position of every cursor. Will never be empty.
*/
private _cursors: Range[] = [new Range(new Position(0, 0), new Position(0, 0))];
private _cursors: Cursor[] = [new Cursor(new Position(0, 0), new Position(0, 0))];
public get cursors(): Range[] {
public get cursors(): Cursor[] {
return this._cursors;
}
public set cursors(value: Range[]) {
public set cursors(value: Cursor[]) {
if (value.length === 0) {
VimState.logger.warn('Tried to set VimState.cursors to an empty array');
return;
}
const map = new Map<string, Range>();
const map = new Map<string, Cursor>();
for (const cursor of value) {
if (!cursor.isValid(this.editor)) {
VimState.logger.warn(`invalid cursor position. ${cursor.toString()}.`);
@ -187,11 +187,11 @@ export class VimState implements vscode.Disposable {
/**
* Initial state of cursors prior to any action being performed
*/
private _cursorsInitialState!: Range[];
public get cursorsInitialState(): Range[] {
private _cursorsInitialState!: Cursor[];
public get cursorsInitialState(): Cursor[] {
return this._cursorsInitialState;
}
public set cursorsInitialState(cursors: Range[]) {
public set cursorsInitialState(cursors: Cursor[]) {
this._cursorsInitialState = [...cursors];
}

View File

@ -3,7 +3,7 @@ import * as vscode from 'vscode';
import { configuration } from './configuration/configuration';
import { VimState } from './state/vimState';
import { visualBlockGetTopLeftPosition, visualBlockGetBottomRightPosition } from './mode/mode';
import { Range } from './common/motion/range';
import { Cursor } from './common/motion/cursor';
import { Position } from 'vscode';
import { Logger } from './util/logger';
import { clamp } from './util/util';
@ -205,15 +205,15 @@ export class TextEditor {
*/
public static *iterateLinesInBlock(
vimState: VimState,
range?: Range,
cursor?: Cursor,
options: { reverse?: boolean } = { reverse: false }
): Iterable<{ line: string; start: Position; end: Position }> {
const { reverse } = options;
range ??= vimState.cursors[0];
cursor ??= vimState.cursors[0];
const topLeft = visualBlockGetTopLeftPosition(range.start, range.stop);
const bottomRight = visualBlockGetBottomRightPosition(range.start, range.stop);
const topLeft = visualBlockGetTopLeftPosition(cursor.start, cursor.stop);
const bottomRight = visualBlockGetBottomRightPosition(cursor.start, cursor.stop);
const [itrStart, itrEnd] = reverse
? [bottomRight.line, topLeft.line]

View File

@ -1,4 +1,4 @@
import { Range } from '../common/motion/range';
import { Cursor } from '../common/motion/cursor';
import { Mode } from '../mode/mode';
import { RegisterMode } from '../register/register';
import { VimState } from '../state/vimState';
@ -204,10 +204,10 @@ export class SelectAnExpandingBlock extends ExpandingSelection {
return !range.failed;
});
let smallestRange: Range | undefined;
let smallestRange: Cursor | undefined;
for (const iMotion of ranges) {
const currentSelectedRange = new Range(
const currentSelectedRange = new Cursor(
vimState.cursorStartPosition,
vimState.cursorStopPosition
);
@ -215,8 +215,8 @@ export class SelectAnExpandingBlock extends ExpandingSelection {
continue;
}
const range = new Range(iMotion.start, iMotion.stop);
let contender: Range | undefined;
const range = new Cursor(iMotion.start, iMotion.stop);
let contender: Cursor | undefined;
if (
range.start.isBefore(currentSelectedRange.start) &&
@ -233,7 +233,7 @@ export class SelectAnExpandingBlock extends ExpandingSelection {
if (contender) {
const areTheyEqual =
contender.equals(new Range(vimState.cursorStartPosition, vimState.cursorStopPosition)) ||
contender.equals(new Cursor(vimState.cursorStartPosition, vimState.cursorStopPosition)) ||
(vimState.currentMode === Mode.VisualLine &&
contender.start.line === vimState.cursorStartPosition.line &&
contender.stop.line === vimState.cursorStopPosition.line);

View File

@ -19,7 +19,7 @@ import { globalState } from '../state/globalState';
import { RecordedState } from '../state/recordedState';
import { TextEditor } from '../textEditor';
import { reportSearch } from '../util/statusBarTextUtils';
import { Range } from '../common/motion/range';
import { Cursor } from '../common/motion/cursor';
import { Position } from 'vscode';
import { VimState } from '../state/vimState';
import { Transformer } from './transformer';
@ -151,7 +151,7 @@ export async function executeTransformations(
switch (transformation.type) {
case 'insertTextVSCode':
await TextEditor.insert(vimState.editor, transformation.text);
vimState.cursors[0] = Range.FromVSCodeSelection(vimState.editor.selection);
vimState.cursors[0] = Cursor.FromVSCodeSelection(vimState.editor.selection);
break;
case 'showCommandHistory':
@ -276,7 +276,7 @@ export async function executeTransformations(
}
const selections = vimState.editor.selections.map((sel) => {
let range = Range.FromVSCodeSelection(sel);
let range = Cursor.FromVSCodeSelection(sel);
if (range.start.isBefore(range.stop)) {
range = range.withNewStop(range.stop.getLeftThroughLineBreaks(true));
}
@ -300,11 +300,11 @@ export async function executeTransformations(
return diffs.reduce(
(cursor, diff) =>
new Range(
new Cursor(
cursor.start.add(vimState.document, diff),
cursor.stop.add(vimState.document, diff)
),
Range.FromVSCodeSelection(sel)
Cursor.FromVSCodeSelection(sel)
);
});

View File

@ -1,5 +1,5 @@
import * as vscode from 'vscode';
import { Range } from '../common/motion/range';
import { Cursor } from '../common/motion/cursor';
import { VimState } from '../state/vimState';
/**
@ -8,8 +8,8 @@ import { VimState } from '../state/vimState';
* wouldn't yet be updated. So we waited for a selection change event, but
* this doesn't seem to be necessary any more.
*/
export function getCursorsAfterSync(): Range[] {
return vscode.window.activeTextEditor!.selections.map((x) => Range.FromVSCodeSelection(x));
export function getCursorsAfterSync(): Cursor[] {
return vscode.window.activeTextEditor!.selections.map((x) => Cursor.FromVSCodeSelection(x));
}
export function clamp(num: number, min: number, max: number) {

View File

@ -2,7 +2,7 @@ import * as assert from 'assert';
import * as vscode from 'vscode';
import { EasyMotion } from '../../src/actions/plugins/easymotion/easymotion';
import { Position } from 'vscode';
import { Range } from '../../src/common/motion/range';
import { Cursor } from '../../src/common/motion/cursor';
import { VimState } from '../../src/state/vimState';
import { setupWorkspace, cleanUpWorkspace } from '../testUtils';
@ -19,7 +19,7 @@ suite('VimState', () => {
await vimState.load();
const cursorStart = new Position(0, 0);
const cursorStop = new Position(0, 1);
const initialCursors = [new Range(cursorStart, cursorStop), new Range(cursorStart, cursorStop)];
const initialCursors = [new Cursor(cursorStart, cursorStop), new Cursor(cursorStart, cursorStop)];
// test
vimState.cursors = initialCursors;
@ -35,8 +35,8 @@ suite('VimState', () => {
const cursorStart = new Position(0, 0);
const cursorStop = new Position(0, 1);
const initialCursors = [
new Range(cursorStart, cursorStop),
new Range(new Position(1, 0), new Position(1, 1)),
new Cursor(cursorStart, cursorStop),
new Cursor(new Position(1, 0), new Position(1, 1)),
];
// test