Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tabbing through VSCode's built-in find and replace menu also runs whatever command is mapped to tab in the editor #7000

Closed
dominicpalmer opened this issue Aug 16, 2021 · 1 comment · Fixed by #8505
Labels

Comments

@dominicpalmer
Copy link
Contributor

dominicpalmer commented Aug 16, 2021

Describe the bug
After remapping tab and shift+tab in vscodevim's normal mode, opening VSCode's built-in find and replace functionality (ordinarily mapped to ctrl+h) and tabbing from the 'find' text box to the 'replace' text box will also run whatever Vim command that tab is mapped to into the editor that called find/replace.

To Reproduce
As an example, I had the following remaps in my settings.json:

  ...
  "vim.leader": " ",
  "vim.normalModeKeyBindingsNonRecursive": [
    // Find and replace
    { "before": ["<leader>", "r"], "commands": ["editor.action.startFindReplaceAction"] }
    // Handle tab key indentation in VSCode as terminals treat ctrl-i and tab the same
    { "before": ["<tab>"], "commands": [">", ">"] },
    { "before": ["<S-tab>"], "after": ["<", "<"] }
   ...

With this in place, in normal mode I can press the tab key to indent immediately. But when I then open up the find and replace window, search a 'find' term and hit tab (at this point focus still on the find and replace window), the find/replace window does tab through to the 'replace' text box as expected, but a side effect is that the actual tab command (in my case, indentation via >>) is also called in the editor. Consistently tabbing through the find and replace menu will then keep indenting the line in the editor that I was last on.

This also appears to happen when calling find and replace from visual mode, if tab is remapped there too:

  "vim.visualModeKeyBindingsNonRecursive": [
    // Line shifting is better handled by VSCode
    { "before": ["J"], "commands": ["editor.action.moveLinesDownAction"] },
    { "before": ["K"], "commands": ["editor.action.moveLinesUpAction"] },
    // Visual mode indentation
    { "before": ["<tab>"], "after": [">", "g", "v"] },
    { "before": ["<S-tab>"], "after": ["<", "g", "v"] },
    { "before": ["u"], "after": ["<Esc>", "u"] },
    // Find and replace
    { "before": ["<leader>", "r"], "commands": ["editor.action.startFindReplaceAction"] },
  ],

In visual mode with the above settings, the visual selection is indented when tabbing through the find and replace menu.

Expected behavior
When focus is on the search/find and replace windows build into VSCode, hitting tab should cycle through the window's options without also running the command that tab is mapped to.

Note that this bug is not present for other built-in VSCode windows such as the quick open menu, the command palette or the tasks menu.

Environment

  • Extension (VsCodeVim) version: v1.21.6
  • VSCode version: 1.59.0, x64
  • OS: Kubuntu Linux

Other notes
It may or may not be relevant that there's a VSCode keybinding when: condition that exists to validate focus on the find menu - findInputFocussed.

@dominicpalmer dominicpalmer changed the title Tabbing through VSCode's built-in find and replace menu also runs whatever command is mapped to tab Tabbing through VSCode's built-in find and replace menu also runs whatever command is mapped to tab in the editor Aug 16, 2021
@devrelm
Copy link
Contributor

devrelm commented Jul 19, 2023

I've been running into this bug for years and just assumed it was within VSCode itself.

To take this down to a minimal-reproducible test case, it looks like this happens regardless of any of your settings in vim.normalModeKeyBindingsNonRecursive.

It looks like it's just a matter of the when clauses on the extensions.vim_tab and extensions.vim_shift+tab keybindings using the editorFocus context instead of editorTextFocus. In fact, every other keybinding that uses one of these two uses editorTextFocus; extensions.vim_tab and extensions.vim_shift+tab are the only two that uses editorFocus

The extensions.vim_tab keybinding was added in 3b25cca (no PR).

The extensions.vim_shift+tab keybinding was later added in #4089.

Updating the when clause in each of those to use editorTextFocus instead of editorFocus appears to fix the issue without affecting command-mode autocomplete.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants