diff --git a/doc/kitty-scrollback.nvim_spec.txt b/doc/kitty-scrollback.nvim_spec.txt index 0adbea22..25630355 100644 --- a/doc/kitty-scrollback.nvim_spec.txt +++ b/doc/kitty-scrollback.nvim_spec.txt @@ -156,7 +156,7 @@ M.setup() *kitty-scrollback.api.setup* M.quit_all() *kitty-scrollback.api.quit_all* - Attempt to gracefully quit Neovim. How do you exit vim? Why would you exit vim? + Attempt to force quit Neovim. How do you exit vim? Why would you exit vim? M.close_or_quit_all() *kitty-scrollback.api.close_or_quit_all* diff --git a/lua/kitty-scrollback/api.lua b/lua/kitty-scrollback/api.lua index 23255f6b..b804e0fc 100644 --- a/lua/kitty-scrollback/api.lua +++ b/lua/kitty-scrollback/api.lua @@ -16,11 +16,9 @@ M.setup = function(private, options) opts = options ---@diagnostic disable-line: unused-local end ----Attempt to gracefully quit Neovim. How do you exit vim? Why would you exit vim? +---Attempt to force quit Neovim. How do you exit vim? Why would you exit vim? M.quit_all = function() - -- quit causes nvim to exit early sometime interrupting underlying copy child process (.e.g, xclip) - -- send sigterm to gracefully terminate - vim.schedule(ksb_kitty_cmds.signal_term_to_kitty_child_process) + ksb_util.quitall() end ---If the current buffer is the paste buffer, then close the window diff --git a/lua/kitty-scrollback/autocommands.lua b/lua/kitty-scrollback/autocommands.lua index f54bd074..0b49c0c1 100644 --- a/lua/kitty-scrollback/autocommands.lua +++ b/lua/kitty-scrollback/autocommands.lua @@ -124,8 +124,16 @@ M.set_yank_post_autocmd = function() if yankevent.regname == '+' then if vim.fn.has('clipboard') > 0 then - -- contents are copied to clipboard, return to kitty - ksb_api.quit_all() + -- Contents are copied to clipboard, return to kitty + -- Previously Kitty was used to quit nvim by sending a SIGTERM signal avoid exiting nvim early. + -- The xclip child process was not spawning quick enough in the TextYankPost autocommand, resulting + -- in content not being copied to the clipboard. This was observed running Ubuntu on UTM. + -- The side effect of this is that the message Vim: Caught deadly signal 'SIGTERM' would briefly + -- flash before exiting kitty-scrollback.nvim. To avoid the deadly signal message and provide time + -- for xclip to start, defer calling quitall by 100 ms + vim.defer_fn(function() + vim.cmd.quitall({ bang = true }) + end, 100) else vim.schedule(function() local prompt_msg = @@ -147,7 +155,7 @@ M.set_yank_post_autocmd = function() ksb_util.restore_and_redraw() local response = vim.fn.confirm(prompt_msg, '&Quit\n&Continue') if response ~= 2 then - ksb_api.quit_all() + ksb_util.quitall() end end) end diff --git a/lua/kitty-scrollback/kitty_commands.lua b/lua/kitty-scrollback/kitty_commands.lua index b6841758..58b5bab6 100644 --- a/lua/kitty-scrollback/kitty_commands.lua +++ b/lua/kitty-scrollback/kitty_commands.lua @@ -96,7 +96,7 @@ local display_error = function(cmd, r) ksb_util.restore_and_redraw() local response = vim.fn.confirm(prompt_msg, '&Quit\n&Continue') if response ~= 2 then - M.signal_term_to_kitty_child_process(true) + ksb_util.quitall() end end @@ -246,7 +246,7 @@ M.send_lines_to_kitty_and_quit = function(lines, execute_command) '--match=id:' .. p.kitty_data.window_id, cmd_str, }) - M.signal_term_to_kitty_child_process() + ksb_util.quitall() end M.send_paste_buffer_text_to_kitty_and_quit = function(execute_command) @@ -285,19 +285,6 @@ M.signal_winchanged_to_kitty_child_process = function() }) end -M.signal_term_to_kitty_child_process = function(force) - if force then - vim.cmd.quitall({ bang = true }) - else - system_handle_error({ - p.kitty_data.kitty_path, - '@', - 'signal-child', - 'SIGTERM', - }) - end -end - M.open_kitty_loading_window = function(env) if p.kitty_loading_winid then M.close_kitty_loading_window(true) diff --git a/lua/kitty-scrollback/launch.lua b/lua/kitty-scrollback/launch.lua index 64efd9ee..e2aba80d 100644 --- a/lua/kitty-scrollback/launch.lua +++ b/lua/kitty-scrollback/launch.lua @@ -332,7 +332,7 @@ M.setup = function(kitty_data_str) .. table.concat(ksb_health.advice().nvim_version) local response = vim.fn.confirm(prompt_msg, '&Quit\n&Continue') if response ~= 2 then - ksb_kitty_cmds.signal_term_to_kitty_child_process(true) + ksb_util.quitall() end end if not ksb_health.check_kitty_version(true) then @@ -342,7 +342,7 @@ M.setup = function(kitty_data_str) .. table.concat(ksb_health.advice().kitty_version) local response = vim.fn.confirm(prompt_msg, '&Quit\n&Continue') if response ~= 2 then - ksb_kitty_cmds.signal_term_to_kitty_child_process(true) + ksb_util.quitall() end end diff --git a/lua/kitty-scrollback/util.lua b/lua/kitty-scrollback/util.lua index 73c22ef2..2dd5939f 100644 --- a/lua/kitty-scrollback/util.lua +++ b/lua/kitty-scrollback/util.lua @@ -77,4 +77,8 @@ M.clear_yank_autocommand_and_get_visual_selection = function() return reginfo.regcontents end +M.quitall = function() + vim.cmd.quitall({ bang = true }) +end + return M diff --git a/tests/kitty-scrollback/kitty_scrollback_demo_spec.lua b/tests/kitty-scrollback/kitty_scrollback_demo_spec.lua index b3168712..16f49c94 100644 --- a/tests/kitty-scrollback/kitty_scrollback_demo_spec.lua +++ b/tests/kitty-scrollback/kitty_scrollback_demo_spec.lua @@ -178,11 +178,6 @@ $ it('should_copy_visual_selection_to_clipboard', function() local paste = function() - -- TODO(#135): github runner has issues accessing the clipboard - -- just hardcode it for now since this test is for primarily for demo purposes anyway - if h.is_github_action then - return 'README.md' - end return vim.fn.getreg('+') end h.feed_kitty({ @@ -194,7 +189,9 @@ $ }, 0) h.assert_screen_equals( h.feed_kitty({ - h.send_without_newline([[printf "\n kitty-scrollback.nvim copied \e[35m]]), + h.with_pause_seconds_before( + h.send_without_newline([[printf "\n kitty-scrollback.nvim copied \e[35m]]) + ), h.with_pause_seconds_before(h.send_without_newline(h.send_as_string(paste())), 1), h.with_pause_seconds_before([[\e[0m to clipboard\n\n"]], 1), }),