leap.nvim icon indicating copy to clipboard operation
leap.nvim copied to clipboard

feat: attempt to hide cursor when leaping

Open mitchellwrosen opened this issue 1 year ago • 9 comments

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.

mitchellwrosen avatar Apr 25 '23 15:04 mitchellwrosen

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).

ggandor avatar Apr 27 '23 22:04 ggandor

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.

folke avatar Apr 28 '23 08:04 folke

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?

ggandor avatar Apr 30 '23 17:04 ggandor

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)

mitchellwrosen avatar May 01 '23 17:05 mitchellwrosen

@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:

  1. save the cursor state
  2. set cursor to invisible cursor
  3. restore cursor state

Now, when both leap or Noice would be doing this, there's a very likely race-condition, where for example:

  1. Noice saves cursor state
  2. Noice sets cursor to NoiceDisabled
  3. Leap saves cursor state (which is now the Noice one)
  4. Noice restores cursor state (back to normal)
  5. 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'].

folke avatar May 02 '23 05:05 folke

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.

ggandor avatar May 02 '23 12:05 ggandor

Ok, I think I've made the requested changes

mitchellwrosen avatar May 06 '23 18:05 mitchellwrosen

But what about the delaying issue mentioned above? @folke could you give us a TLDR on that? :)

ggandor avatar May 09 '23 10:05 ggandor

@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?

mitchellwrosen avatar May 11 '23 13:05 mitchellwrosen

Rendered obsolete by https://github.com/neovim/neovim/pull/27858.

ggandor avatar Mar 30 '24 10:03 ggandor