diff options
author | Gregory Anders <8965202+gpanders@users.noreply.github.com> | 2023-11-08 12:42:47 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-08 12:42:47 -0600 |
commit | 3128cff6b198daabfddeedd382c0b8707319504f (patch) | |
tree | b76b624f75e80016656dc0b8e459dc970bb84e8b | |
parent | bb7324292cda2354511d3332aecb0b9748021764 (diff) | |
download | rneovim-3128cff6b198daabfddeedd382c0b8707319504f.tar.gz rneovim-3128cff6b198daabfddeedd382c0b8707319504f.tar.bz2 rneovim-3128cff6b198daabfddeedd382c0b8707319504f.zip |
fix(clipboard): increase OSC 52 wait timeout (#25936)
When pasting with OSC 52 some terminals show a prompt to the user asking
for permission to read from the system clipboard. When this prompt
appears, 1s is not long enough to wait.
Increase the timeout to 10s and show a message to the user indicating
how to interrupt the wait after 1s.
-rw-r--r-- | runtime/lua/vim/clipboard/osc52.lua | 36 |
1 files changed, 29 insertions, 7 deletions
diff --git a/runtime/lua/vim/clipboard/osc52.lua b/runtime/lua/vim/clipboard/osc52.lua index 0e8f9d378f..78f5754c30 100644 --- a/runtime/lua/vim/clipboard/osc52.lua +++ b/runtime/lua/vim/clipboard/osc52.lua @@ -20,19 +20,41 @@ function M.paste() io.stdout:write('\x1b]52;;?\x1b\\') - vim.wait(1000, function() + local ok, res + + -- Wait 1s first for terminals that respond quickly + ok, res = vim.wait(1000, function() return contents ~= nil end) - -- Delete the autocommand if it didn't already delete itself - pcall(vim.api.nvim_del_autocmd, id) + if res == -1 then + -- If no response was received after 1s, print a message and keep waiting + vim.api.nvim_echo( + { { 'Waiting for OSC 52 response from the terminal. Press Ctrl-C to interrupt...' } }, + false, + {} + ) + ok, res = vim.wait(9000, function() + return contents ~= nil + end) + end - if contents then - return vim.split(contents, '\n') + if not ok then + vim.api.nvim_del_autocmd(id) + if res == -1 then + vim.notify( + 'Timed out waiting for a clipboard response from the terminal', + vim.log.levels.WARN + ) + elseif res == -2 then + -- Clear message area + vim.api.nvim_echo({ { '' } }, false, {}) + end + return 0 end - vim.notify('Timed out waiting for a clipboard response from the terminal', vim.log.levels.WARN) - return 0 + -- If we get here, contents should be non-nil + return vim.split(assert(contents), '\n') end return M |