VSCodeVim / Vim

:star: Vim for Visual Studio Code
http://aka.ms/vscodevim
MIT License
13.73k stars 1.31k forks source link

Add `gB` keybinding for finding the previous match #9008

Open musjj opened 4 months ago

musjj commented 4 months ago

Fix: https://github.com/VSCodeVim/Vim/issues/9000

What this PR does / why we need it:

gb is a nice binding, so the inverse of it would be useful.

You can bind editor.action.addSelectionToPreviousFindMatch in your config, but the nice thing about the built-in gb is that it aligns all the selection ends of the cursors.

Which issue(s) this PR fixes

fixes #9000

Special notes for your reviewer:

HenryTSZ commented 3 months ago

I merged this PR and tested it locally, and found an issue: When the word are not in current view, It flashed the view to the selected word but jump back to the original one.

https://github.com/VSCodeVim/Vim/assets/55341525/cace293c-4a90-4e10-8b7d-fd780292e9c5

I discovered the problem through debugging

https://github.com/VSCodeVim/Vim/blob/3c33d00fdd37ba21d97a6a8c2daa7257d2722867/src/mode/modeHandler.ts#L1472-L1475

You need to add ActionPreviousFindMatch here as well

like this:

      const lastActionRun =
        this.vimState.recordedState.actionsRun[this.vimState.recordedState.actionsRun.length - 1];
      const isLastCursorTracked =
        lastActionRun instanceof ActionOverrideCmdD ||
        lastActionRun instanceof ActionPreviousFindMatch;