@@ -55,6 +55,11 @@ local M = {}
5555--- @field time_budget_ms number
5656--- @field modes string[]
5757
58+ --- @alias FffSelectAction ' edit' | ' split' | ' vsplit' | ' tabedit'
59+
60+ --- @class FffSelectConfig
61+ --- @field pre_select_hook fun ( current_buf : integer , action : FffSelectAction )
62+
5863--- @class FffConfig
5964--- @field base_path string
6065--- @field prompt string
@@ -68,6 +73,7 @@ local M = {}
6873--- @field hl table<string , string>
6974--- @field frecency FffFrecencyConfig
7075--- @field history FffHistoryConfig
76+ --- @field select FffSelectConfig
7177--- @field git table
7278--- @field debug table
7379--- @field logging table
@@ -186,6 +192,42 @@ local function fallback_hl(name)
186192 return resolved_hl or name [# name ]
187193end
188194
195+ --- Find the first visible window with a normal file buffer
196+ --- @return number | nil Window ID of the first suitable window , or nil if none found
197+ local function find_suitable_window ()
198+ local current_tabpage = vim .api .nvim_get_current_tabpage ()
199+ local windows = vim .api .nvim_tabpage_list_wins (current_tabpage )
200+
201+ for _ , win in ipairs (windows ) do
202+ if vim .api .nvim_win_is_valid (win ) then
203+ local buf = vim .api .nvim_win_get_buf (win )
204+ if vim .api .nvim_buf_is_valid (buf ) then
205+ local buftype = vim .api .nvim_get_option_value (' buftype' , { buf = buf })
206+ local modifiable = vim .api .nvim_get_option_value (' modifiable' , { buf = buf })
207+ local filetype = vim .api .nvim_get_option_value (' filetype' , { buf = buf })
208+
209+ local is_picker_window = (
210+ win == M .state .input_win
211+ or win == M .state .list_win
212+ or win == M .state .preview_win
213+ or win == M .state .file_info_win
214+ )
215+
216+ if
217+ (buftype == ' ' or buftype == ' acwrite' )
218+ and modifiable
219+ and not is_picker_window
220+ and filetype ~= ' undotree'
221+ then
222+ return win
223+ end
224+ end
225+ end
226+ end
227+
228+ return nil
229+ end
230+
189231local function init ()
190232 local config = vim .g .fff or {}
191233 local default_config = {
@@ -308,6 +350,21 @@ local function init()
308350 min_combo_count = 3 , -- Minimum selections before combo boost applies (3 = boost starts on 3rd selection)
309351 combo_boost_score_multiplier = 100 , -- Score multiplier for combo matches (files repeatedly opened with same query)
310352 },
353+ select = {
354+ --- @param current_buf integer
355+ --- @param action FffSelectAction
356+ pre_select_hook = function (current_buf , action )
357+ if action ~= ' edit' then return end
358+ local current_buftype = vim .api .nvim_get_option_value (' buftype' , { buf = current_buf })
359+ local current_buf_modifiable = vim .api .nvim_get_option_value (' modifiable' , { buf = current_buf })
360+
361+ -- If current active buffer is not a normal buffer we find a suitable window with a tab otherwise opening a new split
362+ if current_buftype ~= ' ' or not current_buf_modifiable then
363+ local suitable_win = find_suitable_window ()
364+ if suitable_win then vim .api .nvim_set_current_win (suitable_win ) end
365+ end
366+ end ,
367+ },
311368 -- Git integration
312369 git = {
313370 status_text_color = false , -- Apply git status colors to filename text (default: false, only sign column)
0 commit comments