EtiamNullam / deferred-clipboard.nvim

Keep clipboard in sync with Neovim without the peformance hit.
77 stars 2 forks source link

Deferred Clipboard only kicks in after focus is lost at least once #2

Open Taaqif opened 1 year ago

Taaqif commented 1 year ago

Due to syncing Windows and WSL via win32yank.exe, there is a notable lag when copying thing to the clipboard and on WSL, I see a massive improvement in performance when using this plugin! Thank you.

The issue I have is when I open Neovim for the first time, I don't see this performance boost until I at least lose focus once. I believe its due to the fact that schedule_disable_of_continuous_clipboard_sync_on_focus_change only triggers the vim.o.clipboard = nil after either FocusGained or FocusLost

Is it possible to call this earlier in the setup to make the performance boost immediately available rather than having to trigger a FocusLost manually each time

EtiamNullam commented 1 year ago

I'm glad it's useful for you!

So do you still want to use the fallback in case of clients that do not have support for change events? I believe it's not possible until support for focus change events is truly detected - as any of them fire the first time.

If you don't care for fallback just leave clipboard at nil (or "", empty string, default value) as in basic usage example. Though you might want to use the lazy version to also delay the first clipboard access, increasing the startup time.

Taaqif commented 1 year ago

Would it be possible to check the availability of the Focus changed events using something like

local hasFocusEvent = vim.api.nvim_command_output(([[echo exists('##FocusLost')]])
if hasFocusEvent == '1' then
  vim.o.clipboard = nil
end

This should cater for the fallback as the exists command returns only if the client supports the provided command

EtiamNullam commented 1 year ago

It seems to always return 1 for me, even for terminals which don't support it. Does it work for you as expected?

EDIT: Submitted additional issue here: https://github.com/neovim/neovim/issues/21655

EtiamNullam commented 1 year ago

exists cannot be used to determine support of terminal capabilities. Check the linked issue above for more details.

Let's keep the issue open as the issue still stands. Maybe there is still a better solution for it.

Taaqif commented 1 year ago

Ah thats an oversight on my part, the exists command returns true if neovim supports it but that's not to say the terminal does. Thanks for helping me understand that.

Hopefully there is a smarter way to defer the clipboard on startup as its definitely something I find useful. Nonetheless, I will just set my clipboard to nil as i'm using a terminal that does support this.

Thanks again!