diff --git a/src/actions/base.ts b/src/actions/base.ts index 64aa42777..a0a5c61a5 100644 --- a/src/actions/base.ts +++ b/src/actions/base.ts @@ -112,15 +112,6 @@ export class BaseAction { return true; } - public doesRepeatedOperatorApply(vimState: VimState, keysPressed: string[]) { - const prevAction = vimState.recordedState.actionsRun[vimState.recordedState.actionsRun.length - 1]; - return this.isOperator && keysPressed.length === 1 && prevAction - && this.modes.indexOf(vimState.currentMode) !== -1 - // The previous action is the same as the one we're testing - && prevAction.constructor === this.constructor - // The key pressed is the same as the previous action's last key. - && compareKeypressSequence(prevAction.keysPressed.slice(-1), keysPressed); - } public toString(): string { return this.keys.join(""); @@ -166,12 +157,6 @@ export class Actions { result.keysPressed = vimState.recordedState.actionKeys.slice(0); - return result; - } else if (action.doesRepeatedOperatorApply(vimState, keysPressed)) { - const result = new type(); - - result.keysPressed = vimState.recordedState.actionKeys.slice(0); - return result; } diff --git a/src/actions/commands/actions.ts b/src/actions/commands/actions.ts index 1dfd656a6..f21438774 100644 --- a/src/actions/commands/actions.ts +++ b/src/actions/commands/actions.ts @@ -147,6 +147,8 @@ export abstract class BaseCommand extends BaseAction { canBeRepeatedWithDot = false; + // mustBeFirstKey = true; + /** * Run the command a single time. */ @@ -427,6 +429,7 @@ class CommandEsc extends BaseCommand { [""], ]; + mustBeFirstKey = false; runsOnceForEveryCursor() { return false; } public async exec(position: Position, vimState: VimState): Promise { diff --git a/src/actions/commands/insert.ts b/src/actions/commands/insert.ts index ccf1ca3c5..7d5efcce8 100644 --- a/src/actions/commands/insert.ts +++ b/src/actions/commands/insert.ts @@ -23,6 +23,7 @@ class CommandEscInsertMode extends BaseCommand { [""], ]; + mustBeFirstKey = false; runsOnceForEveryCursor() { return false; } public async exec(position: Position, vimState: VimState): Promise { diff --git a/src/actions/operator.ts b/src/actions/operator.ts index e77f4b1a8..c3d395d5e 100644 --- a/src/actions/operator.ts +++ b/src/actions/operator.ts @@ -24,6 +24,9 @@ export class BaseOperator extends BaseAction { multicursorIndex: number | undefined = undefined; public doesActionApply(vimState: VimState, keysPressed: string[]): boolean { + if (this.doesRepeatedOperatorApply(vimState, keysPressed)) { + return true; + } if (this.modes.indexOf(vimState.currentMode) === -1) { return false; } if (!compareKeypressSequence(this.keys, keysPressed)) { return false; } if (vimState.recordedState.actionsRun.length > 0 && @@ -43,6 +46,16 @@ export class BaseOperator extends BaseAction { return true; } + public doesRepeatedOperatorApply(vimState: VimState, keysPressed: string[]) { + const prevAction = vimState.recordedState.actionsRun[vimState.recordedState.actionsRun.length - 1]; + return this.isOperator && keysPressed.length === 1 && prevAction + && this.modes.indexOf(vimState.currentMode) !== -1 + // The previous action is the same as the one we're testing + && prevAction.constructor === this.constructor + // The key pressed is the same as the previous action's last key. + && compareKeypressSequence(prevAction.keysPressed.slice(-1), keysPressed); + } + /** * Run this operator on a range, returning the new location of the cursor. */ diff --git a/src/mode/modeHandler.ts b/src/mode/modeHandler.ts index 2c89015f9..e80dd5efe 100644 --- a/src/mode/modeHandler.ts +++ b/src/mode/modeHandler.ts @@ -680,7 +680,6 @@ export class ModeHandler implements vscode.Disposable { this._vimState.cursorPosition = newPosition; this._vimState.cursorStartPosition = newPosition; - this._vimState.desiredColumn = newPosition.character; // start visual mode?