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

fix keymap retrigger in operator mode

Open nxmxsxs opened this issue 2 years ago • 6 comments

should fix #286.

nxmxsxs avatar Jan 19 '23 20:01 nxmxsxs

I did already fix that, no?

I use mini.ai myself with those keybiondings and it works as expected

folke avatar Jan 19 '23 21:01 folke

yes, you fixed the main problem. However consider this case:

  1. you have the string "hello"
  2. if you try to ciw with the cursor on the character h, you'll actually end up performing the action on the previous character " which happens to be a word in vim

I suspect this happens because c operator enters insert mode so when you retrigger to re-enter normal mode, the cursor shifts backwards by one position.

nxmxsxs avatar Jan 19 '23 21:01 nxmxsxs

Thank you for the clarification. Will need to check this PR with some issues from the past related to keymaps.

I'm also not that sure of the vim.schedule in there

folke avatar Jan 20 '23 15:01 folke

Yeah. I agree with the sentiment about using vim.schedule.

~~I've got another solution via this branch which uses expr and remap to retrigger the original keymap.~~

Edit: I've figured out a better solution for the retrigger logic

nxmxsxs avatar Jan 20 '23 16:01 nxmxsxs

I implemented the solution you propose a while back, but it failed some issues people had in the past. Although, I did not add that <ignore>.

What I'll do first, I'll add a bunch of unit tests for those issues I'm talking about, so we have something to test this with. Will do so on Monday.

folke avatar Jan 21 '23 07:01 folke

Understood. From my various "tests" it works pretty well:

  • loading multiple plugins with one keymap. e.g gzaiw[char] loads mini.surround then mini.ai for me
  • count works as expected

nxmxsxs avatar Jan 21 '23 14:01 nxmxsxs

yes, you fixed the main problem. However consider this case:

  1. you have the string "hello"
  2. if you try to ciw with the cursor on the character h, you'll actually end up performing the action on the previous character " which happens to be a word in vim

I suspect this happens because c operator enters insert mode so when you retrigger to re-enter normal mode, the cursor shifts backwards by one position.

When will this pr be merged? I also encountered this issue.

mathjiajia avatar Feb 05 '23 15:02 mathjiajia

I still need to check existing issues related to keymaps and make sure they still work as expected. If you want to help, add a comment to this PR linking to existing issues I should re-check with this PR

folke avatar Feb 06 '23 08:02 folke

AFAICT, these are the more relevant issues regarding the keys handler:

  • #308
  • #307
  • #286
  • #252
  • #71
  • #28

All of these seems to be fixed using neovim master but not on neovim stable (0.8.x). Particularly:

  • keys need to be pressed twice(sometimes)
    • Upon opening neovim, When I perform any(literally) action, subsequent registered keys need to be pressed twice to trigger
  • keys are pasted when triggering in visual mode.

nxmxsxs avatar Feb 07 '23 14:02 nxmxsxs

ok, thanks. I'll try to look into it later today. I do think the pending keys probably need to be added to your PR, but I'll see if it's needed when I encounter issues

folke avatar Feb 07 '23 15:02 folke

I checked all existing issues and these changes indeed seem to work for all of them. Thanks for fixing this!

folke avatar Feb 07 '23 23:02 folke

Happy to help! Though I did mention that there were some issues with neovim stable. Were you able to verify this?

nxmxsxs avatar Feb 07 '23 23:02 nxmxsxs

It all seemed to work for me on stable. What issue in particular didnt work on stable for you?

folke avatar Feb 08 '23 06:02 folke

This one seems to work on nightly, but not on stable. https://github.com/folke/lazy.nvim/issues/511

Will look into it

folke avatar Feb 08 '23 07:02 folke