fix: remove stale popup buffers (#1530)

* fix: remove stale popup buffers

* fix: restore the logic for updating the buffer

---------

Co-authored-by: yetone <yetoneful@gmail.com>
This commit is contained in:
Kasper Seweryn
2025-03-12 09:43:25 +01:00
committed by GitHub
parent f9ab6934d2
commit c4fa4621fb
2 changed files with 12 additions and 2 deletions

View File

@@ -194,7 +194,9 @@ end
function PromptInput:close_shortcuts_hints()
if self.shortcuts_hints_winid and api.nvim_win_is_valid(self.shortcuts_hints_winid) then
local buf = api.nvim_win_get_buf(self.shortcuts_hints_winid)
api.nvim_win_close(self.shortcuts_hints_winid, true)
api.nvim_buf_delete(buf, { force = true })
self.shortcuts_hints_winid = nil
end
end

View File

@@ -1028,14 +1028,14 @@ function Sidebar:apply(current_cursor)
local function clear_highlights() api.nvim_buf_clear_namespace(bufnr, ns_id, 0, -1) end
-- Create loading indicator float window
local loading_buf = api.nvim_create_buf(false, true)
local loading_buf = nil
local loading_win = nil
local spinner_frames = { "", "", "", "", "", "", "", "" }
local spinner_idx = 1
local loading_timer = nil
local function update_loading_indicator()
if not loading_win or not api.nvim_win_is_valid(loading_win) then return end
if not loading_win or not loading_buf or not api.nvim_win_is_valid(loading_win) then return end
spinner_idx = (spinner_idx % #spinner_frames) + 1
local text = spinner_frames[spinner_idx] .. " Applying changes..."
api.nvim_buf_set_lines(loading_buf, 0, -1, false, { text })
@@ -1066,6 +1066,7 @@ function Sidebar:apply(current_cursor)
zindex = 101,
}
loading_buf = api.nvim_create_buf(false, true)
loading_win = api.nvim_open_win(loading_buf, false, opts)
-- Start timer to update spinner
@@ -1083,6 +1084,11 @@ function Sidebar:apply(current_cursor)
api.nvim_win_close(loading_win, true)
loading_win = nil
end
if loading_buf then
api.nvim_buf_delete(loading_buf, { force = true })
loading_buf = nil
end
end
clear_highlights()
@@ -2792,7 +2798,9 @@ function Sidebar:create_input_container(opts)
-- Close the floating window
local function close_hint()
if hint_window and api.nvim_win_is_valid(hint_window) then
local buf = api.nvim_win_get_buf(hint_window)
api.nvim_win_close(hint_window, true)
api.nvim_buf_delete(buf, { force = true })
hint_window = nil
end
end