diff --git a/src/actions/commands/actions.ts b/src/actions/commands/actions.ts index 368f3c627c0..1ae6d28a3f6 100644 --- a/src/actions/commands/actions.ts +++ b/src/actions/commands/actions.ts @@ -909,7 +909,9 @@ class CommandInsertInSearchMode extends BaseCommand { vimState.globalState.searchStateIndex = vimState.globalState.searchStatePrevious.length - 1; // Move cursor to next match - vimState.cursorStopPosition = searchState.getNextSearchMatchPosition(vimState.cursorStopPosition).pos; + vimState.cursorStopPosition = searchState.getNextSearchMatchPosition( + vimState.cursorStopPosition + ).pos; return vimState; } else if (key === '') { @@ -1067,7 +1069,10 @@ class CommandCmdA extends BaseCommand { public async exec(position: Position, vimState: VimState): Promise { vimState.cursorStartPosition = new Position(0, vimState.desiredColumn); - vimState.cursorStopPosition = new Position(TextEditor.getLineCount() - 1, vimState.desiredColumn); + vimState.cursorStopPosition = new Position( + TextEditor.getLineCount() - 1, + vimState.desiredColumn + ); await vimState.setCurrentMode(ModeName.VisualLine); return vimState; @@ -4039,7 +4044,9 @@ abstract class IncrementDecrementNumberAction extends BaseCommand { start, end ); - vimState.cursorStopPosition = vimState.cursorStopPosition.getLeftByCount(num.suffix.length); + vimState.cursorStopPosition = vimState.cursorStopPosition.getLeftByCount( + num.suffix.length + ); return vimState; } else if (num !== null) { word = word.slice(num.prefix.length + num.value.toString().length); diff --git a/src/actions/operator.ts b/src/actions/operator.ts index fd7dca36396..45334da8fa3 100644 --- a/src/actions/operator.ts +++ b/src/actions/operator.ts @@ -292,9 +292,7 @@ export class YankOperator extends BaseOperator { } if (originalMode === ModeName.Normal && !moveCursor) { - vimState.cursors = vimState.cursorPositionJustBeforeAnythingHappened.map( - x => new Range(x, x) - ); + vimState.cursors = vimState.cursorsInitialState; } else { vimState.cursorStopPosition = start; } diff --git a/src/actions/textobject.ts b/src/actions/textobject.ts index 1b2306a9e9d..83140f5e5a9 100644 --- a/src/actions/textobject.ts +++ b/src/actions/textobject.ts @@ -193,7 +193,10 @@ export class SelectAnExpandingBlock extends ExpandingSelection { let smallestRange: Range | undefined = undefined; for (const iMotion of ranges) { - const currentSelectedRange = new Range(vimState.cursorStartPosition, vimState.cursorStopPosition); + const currentSelectedRange = new Range( + vimState.cursorStartPosition, + vimState.cursorStopPosition + ); if (iMotion.failed) { continue; } @@ -237,7 +240,10 @@ export class SelectAnExpandingBlock extends ExpandingSelection { smallestRange.start.line, smallestRange.start.character ); - vimState.cursorStopPosition = new Position(smallestRange.stop.line, smallestRange.stop.character); + vimState.cursorStopPosition = new Position( + smallestRange.stop.line, + smallestRange.stop.character + ); vimState.recordedState.operatorPositionDiff = undefined; return { start: smallestRange.start, diff --git a/src/configuration/remapper.ts b/src/configuration/remapper.ts index c29d22d6c60..468f9daa176 100644 --- a/src/configuration/remapper.ts +++ b/src/configuration/remapper.ts @@ -137,9 +137,7 @@ export class Remapper implements IRemapper { await vimState.historyTracker.undoAndRemoveChanges( Math.max(0, numCharsToRemove * vimState.cursors.length) ); - vimState.cursors = vimState.cursors.map(x => - x.withNewStop(x.stop.getLeft(numCharsToRemove)) - ); + vimState.cursors = vimState.cursors.map(c => c.withNewStop(c.stop.getLeft(numCharsToRemove))); } // We need to remove the keys that were remapped into different keys from the state. vimState.recordedState.actionKeys = vimState.recordedState.actionKeys.slice( @@ -208,7 +206,9 @@ export class Remapper implements IRemapper { .slice(0, inputtedKeys.length - keySlice.length) .join(''); if (precedingKeys.length > 0 && !/^[0-9]+$/.test(precedingKeys)) { - this._logger.verbose(`key sequences need to match precisely. precedingKeys=${precedingKeys}.`); + this._logger.verbose( + `key sequences need to match precisely. precedingKeys=${precedingKeys}.` + ); break; } } diff --git a/src/jumps/jump.ts b/src/jumps/jump.ts index 48023180dc0..d71b7c3bceb 100644 --- a/src/jumps/jump.ts +++ b/src/jumps/jump.ts @@ -55,7 +55,7 @@ export class Jump { return new Jump({ editor: vimState.editor, fileName: vimState.editor.document.fileName, - position: vimState.cursorPositionJustBeforeAnythingHappened[0], + position: vimState.cursorsInitialState[0].stop, }); } diff --git a/src/mode/modeHandler.ts b/src/mode/modeHandler.ts index d6f96adde98..e63caea8136 100644 --- a/src/mode/modeHandler.ts +++ b/src/mode/modeHandler.ts @@ -263,9 +263,7 @@ export class ModeHandler implements vscode.Disposable { key = ''; } - this.vimState.cursorPositionJustBeforeAnythingHappened = this.vimState.cursors.map( - x => x.stop - ); + this.vimState.cursorsInitialState = this.vimState.cursors; this.vimState.recordedState.commandList.push(key); try { @@ -321,7 +319,7 @@ export class ModeHandler implements vscode.Disposable { } // Catch any text change not triggered by us (example: tab completion). - vimState.historyTracker.addChange(this.vimState.cursorPositionJustBeforeAnythingHappened); + vimState.historyTracker.addChange(this.vimState.cursorsInitialState.map(c => c.stop)); vimState.keyHistory.push(key); @@ -588,7 +586,7 @@ export class ModeHandler implements vscode.Disposable { this.vimState.alteredHistory = false; vimState.historyTracker.ignoreChange(); } else { - vimState.historyTracker.addChange(this.vimState.cursorPositionJustBeforeAnythingHappened); + vimState.historyTracker.addChange(this.vimState.cursorsInitialState.map(c => c.stop)); } } @@ -915,7 +913,9 @@ export class ModeHandler implements vscode.Disposable { vimState.cursorStartPosition = Position.FromVSCodePosition( this.vimState.editor.selection.start ); - vimState.cursorStopPosition = Position.FromVSCodePosition(this.vimState.editor.selection.end); + vimState.cursorStopPosition = Position.FromVSCodePosition( + this.vimState.editor.selection.end + ); break; case 'showCommandHistory': @@ -1168,7 +1168,7 @@ export class ModeHandler implements vscode.Disposable { } vimState.isRunningDotCommand = false; - vimState.cursorPositionJustBeforeAnythingHappened = vimState.cursors.map(x => x.stop); + vimState.cursorsInitialState = vimState.cursors; return vimState; } @@ -1360,7 +1360,9 @@ export class ModeHandler implements vscode.Disposable { searchRanges.push.apply(searchRanges, searchState.matchRanges); - const { start, end, match } = searchState.getNextSearchMatchRange(vimState.cursorStopPosition); + const { start, end, match } = searchState.getNextSearchMatchRange( + vimState.cursorStopPosition + ); if (match) { searchRanges.push(new vscode.Range(start, end)); diff --git a/src/state/vimState.ts b/src/state/vimState.ts index 62c0bdfd80c..d6b8ec85e78 100644 --- a/src/state/vimState.ts +++ b/src/state/vimState.ts @@ -76,6 +76,7 @@ export class VimState implements vscode.Disposable { public alteredHistory = false; public isRunningDotCommand = false; + /** * The last visual selection before running the dot command */ @@ -142,8 +143,6 @@ export class VimState implements vscode.Disposable { this.cursors[0] = this.cursors[0].withNewStop(value); } - - /** * The position of every cursor. */ @@ -163,7 +162,16 @@ export class VimState implements vscode.Disposable { this.isMultiCursor = this._cursors.length > 1; } - public cursorPositionJustBeforeAnythingHappened = [new Position(0, 0)]; + /** + * Initial state of cursors prior to any action being performed + */ + private _cursorsInitialState: Range[]; + public get cursorsInitialState(): Range[] { + return this._cursorsInitialState; + } + public set cursorsInitialState(value: Range[]) { + this._cursorsInitialState = Object.assign([], value); + } public isRecordingMacro: boolean = false; public isReplayingMacro: boolean = false;