feat: handle visual highlight using ModeChanged event
cb54e80 introduce changes to check visual mode highlight using
current_mode, this changes causes a bug with Shift + v (visual
line mode) where the cursor highlight still uses the default Visual
highlight until pressing the second key.
~~Checking visual mode highlights Using key (and checking it inside
current_mode == 'n') is more reliable than using current_mode.~~
Update
We can completely avoid checking key or current_mode for visual highlight by using autocmd on these events:
-
ModeChanged *:[vV\x16]for set highlight -
ModeChanged [vV\x16]:nfor reset
@TheBlob42 can you confirm that this doesn't break your use case?
I'm currently only on my phone, will test it tomorrow
Notice the sign column is highlighted immediately after pressing
v. This happened before this PR, although not until moving the visual selection by one first.
@mvllow isn't that something we introduced in https://github.com/mvllow/modes.nvim/pull/32?
Yea, I think with visual mode it's a little strange (since your current line isn't always highlighted like the other modes) but not a big deal. More of a feature request if anything but also would add more complexity.
@TheBlob42 can you confirm that this doesn't break your use case?
Works fine with vim-cutlass or any other similar mappings for me :+1:
@mvllow @TheBlob42 using autocmd on ModeChanged event seems more reliable than using key or current_mode variable
The autocmd filter is taken from the example in :h ModeChanged, *:[vV\x16] means every time you enter VISUAL{LINE,BLOCK} mode
Now that you mention the ModeChanged event: Is there anything speaking against moving ALL logic from the vim.on_key function to appropriate "ModeChange autocommands" instead? :thinking:
Is there anything speaking against moving ALL logic from the vim.on_key function to appropriate "ModeChange autocommands" instead?
@TheBlob42 you can take a look into https://github.com/fitrh/modes.nvim/tree/feat/modechanged-autocmd, maybe we can discuss this in another issue
I'm going to merge this since I haven't had any issues using it until now