You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Vim f Motion Triggers Context Menu in Visual Mode #568
When using Vim visual mode, the f{char} motion conflicts with the context menu shortcut.
For example, pressing fm should find and highlight the next m character. Instead, the m key triggers the context menu.
Steps to reproduce
Open a note.
Press v to enter visual mode.
Press f.
Press m.
Expected Behaviour
The pending f motion should have higher priority than the context menu shortcut.
Pressing fm should find and highlight the next m character.
Pressing m normally, without a pending f motion, should continue to trigger the context menu.
Actual Behaviour
When f is pressed in visual mode, pressing m triggers the context menu instead of being interpreted as the target character for the pending f motion.
Additional Notes
After fm triggers the context menu, pressing Escape correctly closes the context menu. However, the pending f motion appears to remain active.
For example:
Press v to enter visual mode.
Press m, which opens the context menu.
Press Escape to close the context menu.
Press h.
The h is then treated as the target character for the previous f motion, causing the highlight to move to the next h.
This suggests taht the pending f motion is not being cleared when the context menu interaction occurs.
Suggested Solution
Give a pending Vim f motion higher input priority than the context menu shortcut in visual mode.
When f is awaiting a target character, the next character should be consumed by the Vim motion handler. This would allow fm to find and highlight the next m, while pressing m normally would continue to trigger the context menu.
This preserves the existing context menu shortcut while allowing f{char} motions to work correctly.
Thanks for the unusually precise report: the leak observation (Escape after the menu, then h getting swallowed as the f target) was the detail that pointed at the real layer.
What happened: the visual-mode m context-menu shortcut lives in a window-level keydown listener registered with capture, so it runs before CodeMirror's vim plugin ever sees the event and stops propagation. Vim had already gone pending on f, the m was intercepted for the menu, and the still-pending motion then consumed the first key after the menu closed. Both symptoms, one interception.
Fixed in 9eedf1b on the v2.27.0 branch, along the lines you suggested: the shortcut now checks the vim plugin's own pending state (awaiting a target character after f/t/r, or any buffered prefix like a count or a register) and yields the key to vim when a sequence is in flight. So:
v f m extends the selection to the next m.
d f m, 2 f m, r m and friends all keep their operand too.
A plain m in visual mode still opens the context menu, and the dedicated context-menu key is untouched.
The stale-pending leak is gone structurally: the menu can no longer open mid-sequence.
How to test locally once it ships (or from the branch): with vim mode on, open a note containing a line like alpha m bravo, press 0 then v then f then m. Before: the context menu opens and the selection stays put (and after Escape, the next key jumps the selection). After: the selection extends through the m of "alpha m", no menu. Then press Escape, 0, v, m: the context menu opens as before.
Activity
adibhanna commentedon Aug 10, 2026
Thanks for the unusually precise report: the leak observation (Escape after the menu, then
hgetting swallowed as the f target) was the detail that pointed at the real layer.What happened: the visual-mode
mcontext-menu shortcut lives in a window-level keydown listener registered with capture, so it runs before CodeMirror's vim plugin ever sees the event and stops propagation. Vim had already gone pending onf, themwas intercepted for the menu, and the still-pending motion then consumed the first key after the menu closed. Both symptoms, one interception.Fixed in 9eedf1b on the
v2.27.0branch, along the lines you suggested: the shortcut now checks the vim plugin's own pending state (awaiting a target character afterf/t/r, or any buffered prefix like a count or a register) and yields the key to vim when a sequence is in flight. So:v f mextends the selection to the nextm.d f m,2 f m,r mand friends all keep their operand too.min visual mode still opens the context menu, and the dedicated context-menu key is untouched.How to test locally once it ships (or from the branch): with vim mode on, open a note containing a line like
alpha m bravo, press0thenvthenfthenm. Before: the context menu opens and the selection stays put (and after Escape, the next key jumps the selection). After: the selection extends through themof "alpha m", no menu. Then press Escape,0,v,m: the context menu opens as before.Ships in 2.27.0.
adibhanna commentedon Aug 10, 2026
Closing as fixed by 9eedf1b on the v2.27.0 branch; ships with 2.27.0.
Fix(vim): pending f/t/r motions own the next key over the m menu (Zen…