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

Refactor map implementation and restore which-key compatibility #1029

Merged
merged 13 commits into from
Nov 13, 2024

Conversation

citizenmatt
Copy link
Member

@citizenmatt citizenmatt commented Nov 7, 2024

This PR restores compatibility with idea-which-key, which was broken due to changes to CommandPartNode in #979.

The CommandPartNode<T> classes have been deprecated and reimplemented in terms of a new KeyStrokeTrie<T> class, that efficiently maps sequences of KeyStroke to data T. The trie structure is used to store and look up the builtin Vim commands (represented by a T of LazyVimCommand). The CommandPartNode API is restored to how it was before #979, and should work with the last released version of which-key.

It would be appropriate for which-key to migrate to the new API, which can provide more efficient lookup and iteration.

The new trie structure is now also used for user maps, simplifying and optimising storage and lookup of both finished key sequences and prefixes. While refactoring handling of the map commands, several fixes have been made:

  • Improve the output of maps registered for multiple modes, e.g. vmap for Visual + Select, map for Normal, Visual, Select and Op-pending. The maps will now have the proper character indicator(s), especially when a map is made in multiple modes and then removed in one, e.g. map foo bar followed by sunmap foo will now output nox foo bar
  • Fix a bug that would only show one map with the same left-hand side set of keys. If a map was registered with the same keys in different modes, only one map would be output.
  • Filter map output by prefix (so map foo will show all maps beginning with foo instead of creating a map from foo to <Nop>) - VIM-2981
  • Support map!, unmap! and mapclear! to add a map in Insert+Command-line modes
  • Implement missing smap and snoremap. sunmap was already supported, and mapping to Select mode was already possible with vmap - VIM-2260
  • Fix a bug removing a mapping which had keys that were also a prefix to another mapping

The support for map! required adding the "bang modifier" to the parser, rather than relying on the first character of the trailing string argument - this is required to tell the difference between map! foo bar and map ! foo bar.

The trie is also used in the NERDTree extension

Should also restore compatibility with idea-which-key
E.g. `map foo bar` and `vmap foo baz` would only output one map for `foo` when calling `:map`. Now it will output all maps that match the ex command's modes. This change also improves the marker characters in the first column of map output.
Also supports `mapclear!` and `unmap!`

Moves parsing of the bang modifier to the parser so we can tell the difference between `map! foo bar` and `map ! foo bar`
Support for sunmap and smapclear already exists, and vmap would introduce a Select mode map.

Fixes VIM-2260
Allows iterating the trie entries without having to create a list or create a list for each entry's keystrokes.
@@ -31,7 +31,7 @@ import javax.swing.KeyStroke
/**
* @author vlan
*/
@ExCommand(command = "map,nm[ap],vm[ap],xm[ap],smap,om[ap],im[ap],lm[ap],cm[ap],no[map],nn[oremap],vn[oremap],xn[oremap],snor[emap],ono[remap],no[remap],ino[remap],ln[oremap],cno[remap]")
@ExCommand(command = "map,nm[ap],vm[ap],xm[ap],smap,om[ap],im[ap],lm[ap],cm[ap],nn[oremap],vn[oremap],xn[oremap],snor[emap],ono[remap],no[remap],ino[remap],ln[oremap],cno[remap]")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happened to nomap?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not a Vim command! There's nmap and noremap but no nomap

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh! I can't track the change again, but this is funny :D

@AlexPl292 AlexPl292 merged commit 4b73819 into JetBrains:master Nov 13, 2024
4 checks passed
@citizenmatt citizenmatt deleted the bugfix/which-key-compatibility branch November 13, 2024 17:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants