style is not applied to all windows
Problem
I have this plugin vis-highlights, but there seem to be a problem with styling multiple windows. I've tried to narrow down a test case for this.
Steps to reproduce
I've tried to narrow down the init.lua file that highlights the text down to the following code (rename it to .lua).
Now import init.lua
Open the two files vis f1.txt f2.txt
Run the command e.g. :hi world back:red
Now notice only the current window changes.
If i change window then do a new highlight, strange things are happening.
I'm not sure how this works, is the WIN_HIGHLIGHT event called for all windows automatically or do i have to explicitly traverse windows. Or is this the wrong place to call win:style ? I've tried a few things but nothing seem to work. Maybe I'm doing something else wrong with the style code, but i suspect there might be an error with the way multiple windows is updated based on the win:style and win:style_define.
Init.lua: init.lua.txt
vis version (vis -v)
2d87fdc
Terminal name/version
Ghostty 1fd9cf2d | Wezterm
$TERM environment variable
xterm-ghostty | xterm-256color
The issue is not with applying the styles, but with the way you define them.
You call Window.style_define only once, for the currently focused window win, but then seem to expect the style to be usable in other windows too. As a member of Window, its effect is local to the window you called it on.
A quick fix is to replace, in hi_command,
win:style_define(styleId, style)
with
for w in vis:windows() do
w:style_define(styleId, style)
end
Thank you so much. My plugin now define styles correctly on all windows 🥳