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
5.12k stars 163 forks source link

feature: An API to check if whichkey is open #626

Closed unphased closed 1 month ago

unphased commented 1 month ago

Did you check the docs?

Is your feature request related to a problem? Please describe.

I still think there may already be a way to do this. But I am too dumb to figure it out.

Use case:

Describe the solution you'd like

a way to ask which-key if its popup is currently active

Describe alternatives you've considered

may be able to add my own tracking state of whichkey popup being open if i can set hooks on the events of the popup being opened and closed.

Another workaround is to introduce a sane timeout to both operator pending state (which may be the default, i'm not even sure how to end up in operator pending state when which-key is being used...) and which-key to have a cancel out timeout. I just kinda wanna avoid this as being possibly impractical, because sometimes I really do want to read the whichkey popup for a whole minute to review my keybinds.

Another alternative would be to just feedkey <Esc> (via vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes("<Esc>", true, false, true), "n", true) (attribution: Claude 3.5 Sonnet)) on FocusLost no matter what. I think I will just do this for now. However it is not ideal, as it means I can no longer leave a nvim unfocused in insert mode ready to take a paste or something, and cannot have selection state remain in an unfocused nvim. But I could get used to that maybe.

Additional context

No response

folke commented 1 month ago

This can no longer happen with the rewrite v3 https://github.com/folke/which-key.nvim/pull/624

folke commented 1 month ago

oh, it actually does this as well :) Will see if there's something I can do to fix this. Like close which-key after a certain timeout.

folke commented 1 month ago

Actually, great idea on FocusLost. I'll just close which-key in that case

folke commented 1 month ago

https://github.com/folke/which-key.nvim/commit/9fd4575e3673a8fd1cd832e85e82fb0db3166ab4

unphased commented 1 month ago

Dope... I take it I'll have to wait/upgrade to v3 and then nuke the code I just described above? I'll make a note to self to do that but i suspect the code i described (auto keyfeed Esc on FocusLost) is going to be mostly harmless. Though not being able to select something and unfocus nvim would be a drawback. Oh! Oh! ok i'm going to make my code not feed Esc if mode is visual! Sick.