folke / which-key.nvim

💥 Create key bindings that stick. WhichKey helps you remember your Neovim keymaps, by showing available keybindings in a popup as you type.
Apache License 2.0
4.75k stars 154 forks source link

fix: support nested operators #600

Closed loichyan closed 1 month ago

loichyan commented 2 months ago

If there are nested operators defined (i.e. two operators share the same prefix), for example, when using nvim-surround, the operators could be:

config.operators = {
  y = "Yank",
  yz = "Add surrounding",
}

Currently, which-key.keys.get_operator() loops through all defined operators and selects the first one that is a prefix of prefix_i. However, the order of iteration is random, which means if prefix_i = "yz", it could return either y or yz. If y is returned, prefix_i is split into y and a subsequent z, thus yz won't be shown as an operator.

This PR changes the get_operator() implementation to return the longest defined operator.

folke commented 1 month ago

Thanks!