which-key.nvim icon indicating copy to clipboard operation
which-key.nvim copied to clipboard

fix: support nested operators

Open loichyan opened this issue 3 months ago • 0 comments

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.

loichyan avatar May 13 '24 04:05 loichyan