From 9f83fdcba4f8b8e0f40a40c8361f3e66169fbbe1 Mon Sep 17 00:00:00 2001 From: Eskild Hustvedt Date: Sat, 14 Jun 2025 20:24:09 +0200 Subject: [PATCH] feat: Add config option: sticky_floats - keep floating terminals around when they lose focus (#420) --- doc/toggleterm.txt | 1 + lua/toggleterm.lua | 4 +++- lua/toggleterm/config.lua | 1 + 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/doc/toggleterm.txt b/doc/toggleterm.txt index 9a072b01..ce9f75ca 100644 --- a/doc/toggleterm.txt +++ b/doc/toggleterm.txt @@ -202,6 +202,7 @@ what options are available. It is not written to be used as is. zindex = , title_pos = 'left' | 'center' | 'right', position of the title of the floating window }, + sticky_floats = false, -- if true then floating windows will not be hidden when they lose focus winbar = { enabled = false, name_formatter = function(term) -- term: Terminal diff --git a/lua/toggleterm.lua b/lua/toggleterm.lua index bd03130c..246dbef2 100644 --- a/lua/toggleterm.lua +++ b/lua/toggleterm.lua @@ -116,7 +116,9 @@ local function handle_term_leave() local _, term = terms.identify() if not term then return end if config.persist_mode then term:persist_mode() end - if term:is_float() then term:close() end + if config.sticky_floats == false then + if term:is_float() then term:close() end + end end local function on_term_open() diff --git a/lua/toggleterm/config.lua b/lua/toggleterm/config.lua index 736d8cf8..b66c893d 100644 --- a/lua/toggleterm/config.lua +++ b/lua/toggleterm/config.lua @@ -61,6 +61,7 @@ local config = { shell = vim.o.shell, autochdir = false, auto_scroll = true, + sticky_floats = false, winbar = { enabled = false, name_formatter = function(term) return fmt("%d:%s", term.id, term:_display_name()) end,