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

fix: support nested operators #600

Merged
merged 1 commit into from
Jun 6, 2024
Merged

Conversation

loichyan
Copy link
Contributor

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 folke merged commit 476f4ca into folke:main Jun 6, 2024
@folke
Copy link
Owner

folke commented Jun 6, 2024

Thanks!

@folke folke mentioned this pull request Jun 6, 2024
3 tasks
folke added a commit that referenced this pull request Jun 6, 2024
folke added a commit that referenced this pull request Jun 6, 2024
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.

None yet

2 participants