From 13a70638dc8843de9ca168b0632dfcbee391d9a5 Mon Sep 17 00:00:00 2001 From: YuNing Chen Date: Mon, 30 Sep 2024 16:12:46 +0800 Subject: [PATCH] feat: use vscode native nav back to avoid surpurise and inconsistency - `` now use workbench.action.navigateBack instead of hand rolled jump list, so that `gd` and mouse goto state are consistent. - `` is unchanged and still use hand rolled jump list. --- src/actions/commands/actions.ts | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/actions/commands/actions.ts b/src/actions/commands/actions.ts index 33322a141f2..4f421bdf8a0 100644 --- a/src/actions/commands/actions.ts +++ b/src/actions/commands/actions.ts @@ -1286,9 +1286,9 @@ export class CommandInsertNewLineBefore extends BaseCommand { } @RegisterAction -class CommandNavigateBack extends BaseCommand { +class CommandJumpBack extends BaseCommand { modes = [Mode.Normal]; - keys = [[''], ['']]; + keys = [['']]; override runsOnceForEveryCursor() { return false; @@ -1299,6 +1299,24 @@ class CommandNavigateBack extends BaseCommand { } } +@RegisterAction +class CommandNavigateBack extends BaseCommand { + modes = [Mode.Normal]; + keys = [['']]; + + override isJump = true; + + public override async exec(position: Position, vimState: VimState): Promise { + await vscode.commands.executeCommand('workbench.action.navigateBack'); + + if (vimState.editor === vscode.window.activeTextEditor) { + // We didn't switch to a different editor + vimState.cursorStartPosition = vimState.editor.selection.start; + vimState.cursorStopPosition = vimState.editor.selection.end; + } + } +} + @RegisterAction class CommandNavigateForward extends BaseCommand { modes = [Mode.Normal];