sent_message = true
enddef
-export def Paste(reg: string): tuple<string, list<string>>
+var loop_timerid: number = -1
+
+export def Paste(reg: string): any
# Check if user has indicated that the terminal does not support OSC 52 paste
# (or has disabled it)
if get(g:, 'osc52_disable_paste', 0)
return ("c", [])
endif
+ if loop_timerid != -1
+ # This will result in the register being unchanged
+ return null
+ endif
+
# Some terminals like Kitty respect the selection type parameter on both X11
# and Wayland. If the terminal doesn't then the selection type parameter
# should be ignored (no-op)
endif
endtry
+ # A TextPutPost autocmd may cause this function to be called twice, which is
+ # technically intended behaviour, however it is not necessary for this plugin.
+ # To prevent this, return immediately if we have not returned back to the main
+ # loop since the last "paste" call.
+ loop_timerid = timer_start(0, (_) => {
+ loop_timerid = -1
+ })
+
if interrupt
echo "Interrupted while waiting for OSC 52 response"
return ("c", [""])
call VerifyScreenDump(buf, 'Test_osc52_paste_04', {})
+ " Test that TextPutPost (e.g. from hlyank plugin) doesn't make "paste"
+ " callback be called twice for osc52.
+ call term_sendkeys(buf, "\<Esc>:au TextPutPost * let g:test = 1\<CR>")
+ call TermWait(buf)
+
+ call term_sendkeys(buf, "\"+p")
+ call TermWait(buf)
+
+ call term_sendkeys(buf, "\<Esc>]52;c;" ..
+ \ base64_encode(str2blob(["test"])) .. "\<Esc>\\")
+ call TermWait(buf)
+
+ call VerifyScreenDump(buf, 'Test_osc52_paste_05', {})
+
call StopVimInTerminal(buf)
endfunc