ojroques / nvim-osc52

A Neovim plugin to copy text through SSH with OSC52
BSD 2-Clause "Simplified" License
356 stars 11 forks source link

Unexpected behavior when first invocation is in visual mode #5

Closed arepavich closed 2 years ago

arepavich commented 2 years ago

When nvim-osc52 has not been previously invoked since Neovim was launched, an attempt to invoke it via copy_visual (per the recommended keybindings, <leader>c) does not properly copy the visual selection. Instead, the plugin appears to target results for the most recently used search pattern.

Expected behavior: The visually selected text should be copied to the system clipboard.

Actual behavior (two variants):

  1. The search pattern is found
    • The visual selection is adjusted by the cursor jumping to the pattern's location in the buffer
    • The copied text is the search pattern instead of the visually selected text
  2. The search pattern is not found
    • Neovim throws the following error:
      E5108: Error executing lua: ...are/nvim/site/pack/packer/start/nvim-osc52/lua/osc52.lua:31: Vim(normal):E486: Pattern not found: hello
      stack traceback:
          [C]: in function 'cmd'
          ...are/nvim/site/pack/packer/start/nvim-osc52/lua/osc52.lua:31: in function 'get_text'
          ...are/nvim/site/pack/packer/start/nvim-osc52/lua/osc52.lua:93: in function <...are/nvim/site/pack/packer/start/nvim-osc52/lua/osc52.lua:92>

Any subsequent invocations of nvim-osc52 within the same session appear to be handled properly.

ojroques commented 2 years ago

That's strange, I've never run into this issue. Maybe there is a conflict with another plugin. Can you try disabling your other plugins and see if the problem is still there? Also can you share your Neovim config so that I can reproduce on my side?

arepavich commented 2 years ago

Just tested and confirmed that this issue still persists when nvim-osc52 is the only installed/active plugin.

Interestingly, I have been unable to reproduce this when invoking via command mode with :lua require('osc52').copy_visual() - it only appears to occur when invoked via a keybind.

I tried a different keybind in an attempt to rule out any potential conflicts with Neovim internals (I use , as my leader key, which I've heard can conflict in some cases). For this, I changed the keybind for copy_visual to gac but I saw no change in behavior.

I'm currently using Neovim v0.7.0 and you can find my config here: https://github.com/arepavich/dotfiles/tree/master/config/nvim

ojroques commented 2 years ago

Yeah my bad, I didn't read correctly the doc of visualmode() and it turns out its behavior is different when it is called for the first time. I also forgot that I don't use the mappings directly (I'm using the clipboard provider) so that's why I never saw that bug. Sorry about that.

arepavich commented 2 years ago

Just tested with the latest and I can confirm that it appears to be fixed.

Thanks for making and maintaining this magnificent plugin, by the way; this has been a huge help in my workflow, and the fact that it just works out of the box as a drop-in solution is amazing!

ojroques commented 2 years ago

Great! Thank you, I'm glad you like the plugin :)