Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion lua/command/history.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
51 changes: 45 additions & 6 deletions lua/command/prompt.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down