leap.nvim
leap.nvim copied to clipboard
feat: attempt to hide cursor when leaping
This PR partially addresses #70 by applying a workaround to https://github.com/neovim/neovim/issues/20793 suggested by @folke: just hide and restore the cursor.
The implementation is... weird :/. I've tried to explain what's going on in a comment. Suggestions for wording and/or alternative implementation(s) welcome.
Nice, thank you! I'm totally fine with this for now, one can always set blend
back to a value other than 0 on LeapLeave
. It's enough to give the explanation in the commit message I guess (the comments are great btw), and the highlight stuff directly in the lambdas (a function would be captured in create_autocmd
anyway, so macros are really overkill here).
It's unfortunately not as straightforward. There's some weird bugs in Neovim where cursor updates are delayed. Check the Noice code for more details:
https://github.com/folke/noice.nvim/blob/main/lua/noice/util/hacks.lua#L255-L283
Having Noice with Leap will also lead to issues with this PR since there will likely be race conditions where the wrong cursor is restored.
Would it be possible to set a vim.g....
global that I can set to false from within Noice, to prevent Leap doing the cursor hiding? Alternatively, you could skip hiding the cursor when package.loaded["noice"]
, but I'm happy to do the opposite from Noice as well.
Would it be possible to set a vim.g.... global that I can set to false from within Noice, to prevent Leap doing the cursor hiding? Alternatively, you could skip hiding the cursor when package.loaded["noice"], but I'm happy to do the opposite from Noice as well.
Any of the above is fine, but I'm not sure I understand the implications correctly (sorry, I'm a bit low on mental energy): does this mean that cursor hiding will only work for one of the two plugins?
Hrm... I think if either plugin has to know about each other, that's probably worse than doing nothing in leap, for now - assuming the issue will be addressed in neovim core some time ;).
A third option would be some documentation in the leap README about how one might hide the cursor, with some additional caveats for Noice users.
(But I'm cool with the above suggestions, too - just LMK which to implement, in addition to that macro -> fn
change I still have to make)
@ggandor Noice disables the cursor whenever some code does vim.fn.getchar
, vim.fn.getcharstr
, vim.fn.inputlist
, so the fixes I did were not specifically for leap, but basically for all plugins.
This means that the leap cursor issue doesn't exist for users that also use Noice.
What Noice (and with this PR leap does) when the cursor needs to hide:
- save the cursor state
- set cursor to invisible cursor
- restore cursor state
Now, when both leap or Noice would be doing this, there's a very likely race-condition, where for example:
- Noice saves cursor state
- Noice sets cursor to NoiceDisabled
- Leap saves cursor state (which is now the Noice one)
- Noice restores cursor state (back to normal)
- Leap restores cursor state => will set it to NoiceDisabled
The easiest way would be to skip hiding the cursor in leap when package.loaded['noice']
.
Noice disables the cursor whenever some code does vim.fn.getchar, vim.fn.getcharstr, vim.fn.inputlist, so the fixes I did were not specifically for leap, but basically for all plugins.
Ah, thanks for the clarification, great.
he easiest way would be to skip hiding the cursor in leap when
package.loaded['noice']
.
This is what we'll do then.
Ok, I think I've made the requested changes
But what about the delaying issue mentioned above? @folke could you give us a TLDR on that? :)
@ggandor Ah sorry, I had missed that. Ok, after reading the code, and the issue that lead to some of it (https://github.com/folke/noice.nvim/issues/114), I'm left feeling like I just don't really understand what's going on. I'm happy to drop this feature and say Hiding Cursor in Neovim Considered Too Complicated.
Is anyone else interested in picking up this PR from here?
Rendered obsolete by https://github.com/neovim/neovim/pull/27858.