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
7 changes: 5 additions & 2 deletions lua/fff/picker_ui/picker_ui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,11 @@ local function restore_from_state(state, source_label)
M.state.suggestion_items = state.suggestion_items
M.state.suggestion_source = state.suggestion_source

-- Set the query text in the input buffer
-- Writing the query below triggers on_lines -> on_input_change, which re-runs
-- the search (results may have changed since close). Stash the saved cursor so
-- that re-search restores the position instead of resetting it to the top.
if state.query and state.query ~= '' then
M.state.pending_restore_cursor = M.state.cursor
vim.api.nvim_buf_set_lines(M.state.input_buf, 0, -1, false, { M.state.config.prompt .. state.query })
end

Expand All @@ -186,7 +189,7 @@ local function restore_from_state(state, source_label)
if M.state.active and M.state.input_win and vim.api.nvim_win_is_valid(M.state.input_win) then
local prompt_len = #M.state.config.prompt
vim.api.nvim_win_set_cursor(M.state.input_win, { 1, prompt_len + #state.query })
vim.cmd('startinsert!')
vim.cmd('stopinsert')
end
end)

Expand Down
5 changes: 5 additions & 0 deletions lua/fff/picker_ui/picker_ui_state.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ M.state = {
last_render_ctx = nil,
location = nil,

-- Cursor index to restore after the next search completes (set on resume).
-- Lets the re-search run for fresh results while keeping the saved position.
pending_restore_cursor = nil,

-- History cycling state
history_offset = nil,
next_search_force_combo_boost = false,
Expand Down Expand Up @@ -117,6 +121,7 @@ function M.reset_state()
M.state.item_to_lines = {}
M.state.last_render_ctx = nil
M.state.location = nil
M.state.pending_restore_cursor = nil

M.reset_history_state()

Expand Down
9 changes: 8 additions & 1 deletion lua/fff/picker_ui/search_manager.lua
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,14 @@ function M.update_results_sync()

if S.suggestion_items and #S.suggestion_items > 0 then S.filtered_items = S.suggestion_items end

S.cursor = 1
-- On resume, restore the saved cursor onto the fresh results (clamped, since
-- the result set may have changed since close). Otherwise reset to the top.
if S.pending_restore_cursor then
S.cursor = math.max(1, math.min(S.pending_restore_cursor, #S.filtered_items))
S.pending_restore_cursor = nil
else
S.cursor = 1
end

P.render_debounced()
end
Expand Down