Skip to content

fix(state): defer buffer mappings loading to fix localleader menu#942

Open
niba wants to merge 1 commit into
folke:mainfrom
niba:fix/localleader_popup
Open

fix(state): defer buffer mappings loading to fix localleader menu#942
niba wants to merge 1 commit into
folke:mainfrom
niba:fix/localleader_popup

Conversation

@niba

@niba niba commented Jan 26, 2025

Copy link
Copy Markdown

Description

The ⁠which-key menu fails to appear for ⁠localleader mappings in newly created buffers. Currently, the only way to make it work is to trigger the standard ⁠leader menu first, which seems to force a state update.

It appears that ⁠which-key attempts to load buffer mappings before the ⁠localleader mappings are fully registered. Triggering the ⁠leader menu resolves this because it re-reads the mappings, at which point they are available.

This PR defers the reading of the buffer state. This ensures that all mappings are fully established before ⁠which-key attempts to index them, effectively resolving the race condition.

Related Issue(s)

@github-actions

Copy link
Copy Markdown
Contributor

This PR is stale because it has been open 30 days with no activity.

@github-actions github-actions Bot added the stale This issue or PR has been inactive for a while label Feb 27, 2025
@disrupted

Copy link
Copy Markdown

This PR is stale because it has been open 30 days with no activity.

bad bot

@github-actions github-actions Bot removed the stale This issue or PR has been inactive for a while label Feb 28, 2025
@github-actions

Copy link
Copy Markdown
Contributor

This PR is stale because it has been open 30 days with no activity.

@github-actions github-actions Bot added the stale This issue or PR has been inactive for a while label Mar 30, 2025
@RayJameson

Copy link
Copy Markdown

bump

@github-actions github-actions Bot removed the stale This issue or PR has been inactive for a while label Mar 31, 2025
@github-actions

github-actions Bot commented May 1, 2025

Copy link
Copy Markdown
Contributor

This PR is stale because it has been open 30 days with no activity.

@github-actions github-actions Bot added the stale This issue or PR has been inactive for a while label May 1, 2025
@disrupted

Copy link
Copy Markdown

This PR is stale because it has been open 30 days with no activity.

bad bot

@github-actions github-actions Bot removed the stale This issue or PR has been inactive for a while label May 2, 2025
@github-actions

github-actions Bot commented Jun 1, 2025

Copy link
Copy Markdown
Contributor

This PR is stale because it has been open 30 days with no activity.

@github-actions github-actions Bot added the stale This issue or PR has been inactive for a while label Jun 1, 2025
@niba

niba commented Jun 1, 2025

Copy link
Copy Markdown
Author

ping

@github-actions github-actions Bot removed the stale This issue or PR has been inactive for a while label Jun 2, 2025
@github-actions

github-actions Bot commented Jul 3, 2025

Copy link
Copy Markdown
Contributor

This PR is stale because it has been open 30 days with no activity.

@github-actions github-actions Bot added the stale This issue or PR has been inactive for a while label Jul 3, 2025
@niba

niba commented Jul 3, 2025

Copy link
Copy Markdown
Author

bump

@RayJameson

Copy link
Copy Markdown

@folke I'm sorry for pinging, but do you mind looking at this PR?

@github-actions github-actions Bot removed the stale This issue or PR has been inactive for a while label Jul 4, 2025
@github-actions

github-actions Bot commented Aug 3, 2025

Copy link
Copy Markdown
Contributor

This PR is stale because it has been open 30 days with no activity.

@github-actions github-actions Bot added the stale This issue or PR has been inactive for a while label Aug 3, 2025
@disrupted

Copy link
Copy Markdown

this is getting tiring

@github-actions github-actions Bot removed the stale This issue or PR has been inactive for a while label Aug 5, 2025
@github-actions

github-actions Bot commented Sep 5, 2025

Copy link
Copy Markdown
Contributor

This PR is stale because it has been open 30 days with no activity.

@github-actions github-actions Bot added the stale This issue or PR has been inactive for a while label Sep 5, 2025
@niba

niba commented Sep 5, 2025

Copy link
Copy Markdown
Author

bump

@niba niba force-pushed the fix/localleader_popup branch from d82109f to 71d43fe Compare December 11, 2025 21:06
@github-actions github-actions Bot added the size/s Small PR (<10 lines changed) label Dec 11, 2025
@niba

niba commented Dec 11, 2025

Copy link
Copy Markdown
Author

If anyone wants to use this version, you can add the following to your config:

 {
    "folke/which-key.nvim",
    url = "https://github.com/niba/which-key.nvim",
    branch = "fix/localleader_popup",
 }

@MamaTierra

Copy link
Copy Markdown

If anyone wants to use this version, you can add the following to your config:

 {
    "folke/which-key.nvim",
    url = "https://github.com/niba/which-key.nvim",
    branch = "fix/localleader_popup",
 }

Works for me. Waiting for the merge 👀

felixge added a commit to felixge/dotfiles that referenced this pull request Mar 30, 2026
Race condition: grug-far creates the buffer and displays it (triggering
BufEnter) before calling setupBuffer() which sets the \r, \s, etc.
keymaps. By that time which-key has already scanned and cached an empty
tree for the \ prefix, so pressing localleader never shows the popup.

This is a known which-key bug affecting any plugin that sets buffer-local
<localleader> keymaps after the buffer is displayed:
- folke/which-key.nvim#1029 (grug-far specific)
- folke/which-key.nvim#942 (attempted upstream fix)
- folke/which-key.nvim#476
- folke/which-key.nvim#150

Fix by adding a plugin config override for grug-far that registers a
FileType autocmd to defer clearing the which-key cache, allowing it to
rescan after keymaps are in place. The autocmd is only created when
grug-far loads.

Prompts:

> When using grug in neovim, I find the local leader doesn't work. E.g. I
> add sth to the search and to the replace box, then type \ for local leader,
> and no keymap comes up. But if I do g? for help first, it starts working.
> Debug with tmux

> Search online if other people hit the same issue with grug / lazyvim

> Update the commit message to include the links to the issues and PRs.

> Could the autocmd be defined so it only gets setup when the grug plugin
> gets loaded?
@Wikiwix

Wikiwix commented Mar 31, 2026

Copy link
Copy Markdown

I hope this can be merged at some point.

Until then @felixge's workaround in felixge/dotfiles@eaa1492 is a little less intrusive then using the branch :)

@RayJameson

Copy link
Copy Markdown

I hope this can be merged at some point.

Until then @felixge's workaround in felixge/dotfiles@eaa1492 is a little less intrusive then using the branch :)

IMO it's fine using fork (you can just fork it yourself if you have any concerns) the plugin didn't have new commits which change anything for over 6 months

It would become tedious to edit the config every time you add new plugin with localleader mappings or if you decide to remap them yourself.

@Wikiwix

Wikiwix commented Apr 5, 2026

Copy link
Copy Markdown

I hope this can be merged at some point.
Until then @felixge's workaround in felixge/dotfiles@eaa1492 is a little less intrusive then using the branch :)

IMO it's fine using fork (you can just fork it yourself if you have any concerns) the plugin didn't have new commits which change anything for over 6 months

It would become tedious to edit the config every time you add new plugin with localleader mappings or if you decide to remap them yourself.

I fully agree. Just a matter of which trade off one prefers (I don't have other plugins having trouble), and this way I keep checking for upstream updates of which-key automatically.

Perhaps we get this merged at some point :) 🤞

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/s Small PR (<10 lines changed)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: which-key menu not showing up for <localleader> mappings

5 participants