diff --git a/lua/command/history.lua b/lua/command/history.lua index 3819594..318e0e4 100644 --- a/lua/command/history.lua +++ b/lua/command/history.lua @@ -249,7 +249,13 @@ function M.search(callback) callback(selected[1]) end end, - }, + -- Add a quit action that calls the callback with nil + -- This ensures the prompt is recreated on escape + ["quit"] = function() + callback(nil) + return true -- Return true to close fzf + end + } } -- Position below prompt if it exists, matching its dimensions diff --git a/lua/command/prompt.lua b/lua/command/prompt.lua index 11e46b3..e6a01c7 100644 --- a/lua/command/prompt.lua +++ b/lua/command/prompt.lua @@ -61,9 +61,17 @@ function M.create(opts) return nil end - -- Set window-local options for text handling + -- Set window-local options vim.api.nvim_set_option_value('wrap', false, { win = win }) + -- Explicitly disable statusline to prevent it from being shown after fzf + vim.api.nvim_win_set_option(win, 'statusline', '') + + -- Ensure minimal UI is applied + local win_config = vim.api.nvim_win_get_config(win) + win_config.style = 'minimal' + vim.api.nvim_win_set_config(win, win_config) + -- 6. Register in state state.add_window({ name = WINDOW_NAME, @@ -219,15 +227,46 @@ function M.search_history() return end - history.search(function(selected_cmd) - if selected_cmd and vim.api.nvim_buf_is_valid(window.buf) then - utils.set_cmd_prompt(window.buf, window.win, selected_cmd) + -- Save current content and options + local content = '' + local win_opts = {} + + if vim.api.nvim_buf_is_valid(window.buf) then + local lines = vim.api.nvim_buf_get_lines(window.buf, 0, -1, false) + content = lines[1] or '' + win_opts = window.opts or {} + end + + -- Close the window to avoid statusline leaking + if vim.api.nvim_win_is_valid(window.win) then + vim.api.nvim_win_close(window.win, true) + end + + -- Remove from state + state.remove_window(WINDOW_NAME) + + -- Simple callback that recreates the window and restores content + local function on_history_selection(selected_cmd) + -- Always recreate the window + local new_win = M.create(win_opts) + + if new_win then + -- Set the prompt content + if selected_cmd then + utils.set_cmd_prompt(new_win.buf, new_win.win, selected_cmd) + else + utils.set_cmd_prompt(new_win.buf, new_win.win, content) + end + -- Attach ghost text if enabled if config.values.ui.prompt.ghost_text then - ghost_text.update(window.buf) + ghost_text.update(new_win.buf) end end - end) + end + + -- Call history search with the callback + history.search(on_history_selection) end ---Accepts the ghost text suggestion