Skip to content
Draft
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
6 changes: 0 additions & 6 deletions .luarc.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,6 @@
"version": "LuaJIT"
},
"workspace": {
"library": [
"/opt/homebrew/share/nvim/runtime/lua/vim/_meta",
"/opt/homebrew/share/nvim/runtime/lua/vim/shared.lua",
"${3rd}/luv/library",
"${3rd}/busted/library"
],
"checkThirdParty": false
},
"diagnostics": {
Expand Down
8 changes: 6 additions & 2 deletions lua/fff/main.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
local M = {}

M.state = { initialized = false }

--- Setup the file picker with the given configuration
--- @param config table Configuration options
function M.setup(config) vim.g.fff = config end
Expand Down Expand Up @@ -41,6 +39,12 @@ function M.live_grep(opts)
picker_ui.open(picker_opts)
end

--- Resume the last search.
--- @param opts? table Optional configuration overrides.
function M.resume(opts)
require('fff.picker_ui').open(opts, true)
end

--- Changes the directory indexed by the file picker to the git root and opens the file picker
--- @deprecated Use `find_files` instead
function M.find_in_git_root()
Expand Down
30 changes: 18 additions & 12 deletions lua/fff/picker_ui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,6 @@ function M.create_ui()
preview.set_preview_window(M.state.preview_win)

M.update_results_sync()
M.clear_preview()
M.update_status()

return true
Expand Down Expand Up @@ -2463,6 +2462,12 @@ function M.close()
end
end

-- Clean up picker focus autocmds
pcall(vim.api.nvim_del_augroup_by_name, 'fff_picker_focus')
end

--- Reset picker state
function M.reset_state()
if M.state.preview_timer then
M.state.preview_timer:stop()
M.state.preview_timer:close()
Expand Down Expand Up @@ -2498,8 +2503,6 @@ function M.close()
M.state.combo_visible = true
M.state.combo_initial_cursor = nil
M.reset_history_state()
-- Clean up picker focus autocmds
pcall(vim.api.nvim_del_augroup_by_name, 'fff_picker_focus')
end

--- Helper function to determine current file cache for deprioritization
Expand Down Expand Up @@ -2555,7 +2558,9 @@ end
--- @param location table|nil Pre-fetched location data
--- @param merged_config table Merged configuration
--- @param current_file_cache string|nil Current file cache
local function open_ui_with_state(query, results, location, merged_config, current_file_cache)
--- @param resume? boolean Resume previous search
local function open_ui_with_state(query, results, location, merged_config, current_file_cache, resume)
if not resume then M.reset_state() end
M.state.config = merged_config

if not M.create_ui() then
Expand All @@ -2569,10 +2574,9 @@ local function open_ui_with_state(query, results, location, merged_config, curre
-- Set up initial state
if query then
M.state.query = query
vim.api.nvim_buf_set_lines(M.state.input_buf, 0, -1, false, { M.state.config.prompt .. query })
else
M.state.query = ''
resume = false
end
vim.api.nvim_buf_set_lines(M.state.input_buf, 0, -1, false, { M.state.config.prompt .. M.state.query })

if results then
-- Use prefetched results
Expand All @@ -2584,7 +2588,7 @@ local function open_ui_with_state(query, results, location, merged_config, curre
M.render_list()
M.update_preview()
M.update_status()
else
elseif not resume then
M.update_results()
M.clear_preview()
M.update_status()
Expand Down Expand Up @@ -2612,8 +2616,9 @@ end
--- @param query string The search query to execute
--- @param callback function Function called with results: function(results, metadata, location, get_file_score) -> boolean
--- @param opts? table Optional configuration to override defaults (same as M.open)
--- @param resume? boolean Resume previous search
--- @return boolean true if callback handled results, false if UI was opened
function M.open_with_callback(query, callback, opts)
function M.open_with_callback(query, callback, opts, resume)
if M.state.active then return false end

local merged_config, base_path = initialize_picker(opts)
Expand All @@ -2636,14 +2641,15 @@ function M.open_with_callback(query, callback, opts)
end

if callback_handled then return true end
open_ui_with_state(query, results, location, merged_config, current_file_cache)
open_ui_with_state(query, results, location, merged_config, current_file_cache, resume)

return false
end

--- Open the file picker UI
--- @param opts? {cwd?: string, title?: string, prompt?: string, max_results?: number, max_threads?: number, layout?: {width?: number|function, height?: number|function, prompt_position?: string|function, preview_position?: string|function, preview_size?: number|function}, renderer?: table, mode?: string, grep_config?: table, query?: string} Optional configuration to override defaults
function M.open(opts)
--- @param resume? boolean Resume previous search
function M.open(opts, resume)
if M.state.active then return end

M.state.selected_files = {}
Expand All @@ -2669,7 +2675,7 @@ function M.open(opts)

local current_file_cache = get_current_file_cache(base_path)
local query = opts and opts.query or nil ---@type string|nil
return open_ui_with_state(query, nil, nil, merged_config, current_file_cache)
return open_ui_with_state(query, nil, nil, merged_config, current_file_cache, resume)
end

--- Change the base directory for the file picker
Expand Down
Loading