@@ -2083,6 +2083,19 @@ function M.recall_query_from_history()
20832083 end )
20842084end
20852085
2086+ local suitable_buftypes = {
2087+ [' ' ] = true ,
2088+ terminal = true ,
2089+ acwrite = true ,
2090+ }
2091+
2092+ --- Check if a buffer type is suitable
2093+ --- @param buftype string
2094+ --- @return boolean | nil
2095+ local function is_suitable_buftype (buftype )
2096+ return suitable_buftypes [buftype ]
2097+ end
2098+
20862099--- Find the first visible window with a normal file buffer
20872100--- @return number | nil Window ID of the first suitable window , or nil if none found
20882101local function find_suitable_window ()
@@ -2094,7 +2107,6 @@ local function find_suitable_window()
20942107 local buf = vim .api .nvim_win_get_buf (win )
20952108 if vim .api .nvim_buf_is_valid (buf ) then
20962109 local buftype = vim .api .nvim_get_option_value (' buftype' , { buf = buf })
2097- local modifiable = vim .api .nvim_get_option_value (' modifiable' , { buf = buf })
20982110 local filetype = vim .api .nvim_get_option_value (' filetype' , { buf = buf })
20992111
21002112 local is_picker_window = (
@@ -2105,8 +2117,7 @@ local function find_suitable_window()
21052117 )
21062118
21072119 if
2108- (buftype == ' ' or buftype == ' acwrite' )
2109- and modifiable
2120+ is_suitable_buftype (buftype )
21102121 and not is_picker_window
21112122 and filetype ~= ' undotree'
21122123 then
@@ -2299,10 +2310,8 @@ function M.select(action)
22992310 if action == ' edit' then
23002311 local current_buf = vim .api .nvim_get_current_buf ()
23012312 local current_buftype = vim .api .nvim_get_option_value (' buftype' , { buf = current_buf })
2302- local current_buf_modifiable = vim .api .nvim_get_option_value (' modifiable' , { buf = current_buf })
2303-
2304- -- If current active buffer is not a normal buffer we find a suitable window with a tab otherwise opening a new split
2305- if current_buftype ~= ' ' or not current_buf_modifiable then
2313+ -- If current active buffer is not a suitable buffer we find a suitable window with a tab otherwise opening a new split
2314+ if not is_suitable_buftype (current_buftype ) then
23062315 local suitable_win = find_suitable_window ()
23072316 if suitable_win then vim .api .nvim_set_current_win (suitable_win ) end
23082317 end
0 commit comments