Ver Fonte

fix(neovim): improve floating terminal escapes

Joe há 6 meses atrás
pai
commit
a55e1d1b86
1 ficheiros alterados com 17 adições e 2 exclusões
  1. 17 2
      .config/nvim/lua/plugins/floatingterminal.lua

+ 17 - 2
.config/nvim/lua/plugins/floatingterminal.lua

@@ -88,10 +88,25 @@ return {
             MakeTerm("sto", "Theta", "lazygit", true)
 
             -- Keymaps
-            vim.keymap.set("t", "<Esc><Esc>", lab.close_all)
-            vim.keymap.set("t", "<Esc><Space>", "<Esc>")
             vim.keymap.set("t", "<C-S-t>", "<C-\\><C-n>")
             vim.keymap.set("t", "<S-Space>", "<Esc>")
+            -- Double-tapping <Esc> within 150ms closes floating terminals;
+            -- implemented as a timer to minimize normal <ESC> interruptions
+            local timer_var = "lab_doubletap_timer"
+            vim.keymap.set("t", "<Esc>", function()
+              if vim.b[timer_var] then
+                vim.fn.timer_stop(vim.b[timer_var])
+                vim.b[timer_var] = nil
+                lab.close_all()
+              else
+                vim.b[timer_var] = vim.fn.timer_start(150, function()
+                  vim.b[timer_var] = nil
+                    vim.api.nvim_chan_send(
+                        vim.b.terminal_job_id,
+                        vim.api.nvim_replace_termcodes("<Esc>", true, false, true))
+                end)
+              end
+            end, { noremap = true, silent = true})
         end
     }
 }