Skip to content

Commit eb5f2b3

Browse files
authored
refactor: move change_indexing_directory to picker_ui module (#286)
* refactor: move change_indexing_directory to picker_ui module closes #237 * chore: format * chore: format
1 parent fcdf4a9 commit eb5f2b3

File tree

2 files changed

+37
-25
lines changed

2 files changed

+37
-25
lines changed

lua/fff/main.lua

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -165,11 +165,12 @@ function M.find_files_in_dir(directory)
165165
return
166166
end
167167

168-
M.change_indexing_directory(directory)
169-
170168
local picker_ok, picker_ui = pcall(require, 'fff.picker_ui')
171169
if picker_ok then
172-
picker_ui.open({ title = 'Files in ' .. vim.fn.fnamemodify(directory, ':t') })
170+
picker_ui.open({
171+
title = 'Files in ' .. vim.fn.fnamemodify(directory, ':t'),
172+
cwd = directory,
173+
})
173174
else
174175
vim.notify('Failed to load picker UI', vim.log.levels.ERROR)
175176
end
@@ -179,28 +180,9 @@ end
179180
--- @param new_path string New directory path to use as base
180181
--- @return boolean `true` if successful, `false` otherwise
181182
function M.change_indexing_directory(new_path)
182-
if not new_path or new_path == '' then
183-
vim.notify('Directory path is required', vim.log.levels.ERROR)
184-
return false
185-
end
186-
187-
local expanded_path = vim.fn.expand(new_path)
188-
189-
if vim.fn.isdirectory(expanded_path) ~= 1 then
190-
vim.notify('Directory does not exist: ' .. expanded_path, vim.log.levels.ERROR)
191-
return false
192-
end
193-
194-
local fuzzy = require('fff.core').ensure_initialized()
195-
local ok, result = pcall(fuzzy.restart_index_in_path, expanded_path)
196-
if not ok then
197-
vim.notify('Failed to change directory: ' .. result, vim.log.levels.ERROR)
198-
return false
199-
end
200-
201-
local config = require('fff.conf').get()
202-
config.base_path = expanded_path
203-
return true
183+
local picker_ok, picker_ui = pcall(require, 'fff.picker_ui')
184+
if picker_ok then return picker_ui.change_indexing_directory(new_path) end
185+
return false
204186
end
205187

206188
--- Opens the file under the cursor with an optional callback if the only file

lua/fff/picker_ui.lua

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2601,6 +2601,8 @@ function M.open(opts)
26012601
local merged_config, base_path = initialize_picker(opts)
26022602
if not merged_config then return end
26032603

2604+
if base_path then M.change_indexing_directory(base_path) end
2605+
26042606
-- Initialize grep_mode to first configured mode when opening in grep mode
26052607
if M.state.mode == 'grep' then
26062608
-- Use grep_config.modes if provided, otherwise fall back to global config
@@ -2616,6 +2618,34 @@ function M.open(opts)
26162618
return open_ui_with_state(query, nil, nil, merged_config, current_file_cache)
26172619
end
26182620

2621+
--- Change the base directory for the file picker
2622+
--- @param new_path string New directory path to use as base
2623+
--- @return boolean `true` if successful, `false` otherwise
2624+
function M.change_indexing_directory(new_path)
2625+
if not new_path or new_path == '' then
2626+
vim.notify('Directory path is required', vim.log.levels.ERROR)
2627+
return false
2628+
end
2629+
2630+
local expanded_path = vim.fn.expand(new_path)
2631+
2632+
if vim.fn.isdirectory(expanded_path) ~= 1 then
2633+
vim.notify('Directory does not exist: ' .. expanded_path, vim.log.levels.ERROR)
2634+
return false
2635+
end
2636+
2637+
local fuzzy = require('fff.core').ensure_initialized()
2638+
local ok, result = pcall(fuzzy.restart_index_in_path, expanded_path)
2639+
if not ok then
2640+
vim.notify('Failed to change directory: ' .. result, vim.log.levels.ERROR)
2641+
return false
2642+
end
2643+
2644+
local config = require('fff.conf').get()
2645+
config.base_path = expanded_path
2646+
return true
2647+
end
2648+
26192649
function M.monitor_scan_progress(iteration)
26202650
if not M.state.active then return end
26212651

0 commit comments

Comments
 (0)