Add clickable regions to statusline with %[FuncName] item#19841
Add clickable regions to statusline with %[FuncName] item#19841mattn wants to merge 8 commits intovim:masterfrom
Conversation
Add support for clickable regions in the statusline using the %@funcName@ syntax. When a user clicks on a region, the specified Vim function is called with a dictionary containing click details (button, nclicks, modifiers, minwid, winid). The function can return non-zero to trigger a statusline redraw. - Add %@funcName@ and %@@ (end region) parsing in build_stl_str_hl() - Add stl_click_handler() in mouse.c to dispatch clicks to callbacks - Store resolved click regions per window (w_stl_click) - Add 'statusline_click' feature flag for has() detection - Add 'statuslineclick' option to statuslineopt for enable/disable - Add documentation and tests
Use %[FuncName] to start a clickable region and %[] to end it, instead of %@funcName@ and %@@. This avoids conflict with the existing %@ line break notation and works with :set without needing to escape special characters.
Rename parameters mouse_col and mod_mask to mcol and mods to avoid shadowing the global variables with the same names.
|
I plan to add clickable region support for |
- Fix -Wshadow in win_free(): remove inner 'int i' that shadows outer - Fix -Wunused-parameter in stl_click_handler(): cast params to void when FEAT_EVAL is not defined (tiny build)
|
Thanks, unfortunately ASAN detected a memory leak. |
|
thanks, but I think we should try to be compatible with Neovim here and I believe they are using the |
|
But the arguments passed to the function is also different: So using the same atom doesn't really help (and may lead to user mistakes). |
|
Note that Neovim's statusline click handler uses
The |
|
Also, the callback currently receives a single Dictionary argument with no room for additional parameters in the future. It might be worth considering whether the signature should be extensible (e.g., allowing additional arguments to be added later without breaking existing callbacks). |
|
I see, makes sense. But I don't understand the comment about extending the dictionary in the future. We can simply add new keys in the future, right? So it should be fine as is. |
|
Yes, exactly. My point was that Neovim's positional arguments approach would require changing the interface when extending, whereas the dictionary approach we use here allows adding new keys without breaking existing callbacks. So we're on the same page. |
|
Thanks, I think this is fine now |
|
@mattn I was looking into adding support to vim-airline, but how does the function know the field value for which it has been defined? E.g. for Neovim I know the |
|
@chrisbra Same idea as Neovim — use |
|
ah, makes sense. Thanks |
|
but it doesn't seem to work in the tabline? |
related: #19841 Signed-off-by: Christian Brabandt <cb@256bit.org>
|
Confirmed — the tabline path in |
Problem: Cannot handle mouseclicks in the tabline
Solution: Support %[FuncName] click regions in 'tabline', add "area" key
to the click info dict (Yasuhiro Matsumoto).
The previous implementation resolved and stored click regions only for
per-window statuslines; the tabline path in win_redr_custom() (wp==NULL)
parsed %[FuncName] but discarded the regions, and tabline clicks were
dispatched via TabPageIdxs[] which didn't know about them.
Add a global tabline_stl_click array populated from the tabline path,
refactor stl_click_handler() to take the regions directly, and dispatch
matching clicks from do_mouse() before falling through to tab selection.
The winid entry in the callback dict is 0 for tabline clicks.
related: #19841
closes: #19950
Supported by AI.
Signed-off-by: Yasuhiro Matsumoto <mattn.jp@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
Add support for clickable regions in the statusline using
%[FuncName]syntax. When a user clicks on a region, the specified Vim function is called with a dictionary argument. The function can return non-zero to trigger a statusline redraw.%[FuncName]starts a clickable region,%[]ends it. If%[]is omitted, the region extends to the end of the statusline.%N[FuncName]passes an identifier N to the callback asminwid.The callback receives a Dictionary with:
minwid: identifier from%N[Func](0 if not specified)nclicks: number of clicks (1, 2, or 3)button:"l"(left),"m"(middle),"r"(right)mods: modifier keys, combination of"s"(shift),"c"(ctrl),"a"(alt)winid: window-ID of the clicked statuslineUse
has('statusline_click')to check availability.2026-03-26.231437.mp4