17
17
18
18
--- Get all windows in the current tabpage that aren't NvimTree.
19
19
--- @return table with valid win_ids
20
- local function selectable_win_ids ()
20
+ local function usable_win_ids ()
21
21
local tabpage = api .nvim_get_current_tabpage ()
22
22
local win_ids = api .nvim_tabpage_list_wins (tabpage )
23
23
local tree_winid = view .get_winnr (tabpage )
@@ -36,12 +36,23 @@ local function selectable_win_ids()
36
36
end , win_ids )
37
37
end
38
38
39
- --- Get user to pick a selectable window.
39
+ --- Find the first window in the tab that is not NvimTree.
40
+ --- @return integer -1 if none available
41
+ local function first_win_id ()
42
+ local selectable = usable_win_ids ()
43
+ if # selectable > 0 then
44
+ return selectable [1 ]
45
+ else
46
+ return - 1
47
+ end
48
+ end
49
+
50
+ --- Get user to pick a window in the tab that is not NvimTree.
40
51
--- @return integer | nil -- If a valid window was picked , return its id. If an
41
52
--- invalid window was picked / user canceled, return nil. If there are
42
53
--- no selectable windows, return -1.
43
- local function pick_window ()
44
- local selectable = selectable_win_ids ()
54
+ local function pick_win_id ()
55
+ local selectable = usable_win_ids ()
45
56
46
57
-- If there are no selectable windows: return. If there's only 1, return it without picking.
47
58
if # selectable == 0 then
@@ -160,21 +171,17 @@ local function get_target_winid(mode, win_ids)
160
171
if not M .window_picker .enable or mode == " edit_no_picker" then
161
172
target_winid = lib .target_winid
162
173
163
- -- find the first available window
174
+ -- first available window
164
175
if not vim .tbl_contains (win_ids , target_winid ) then
165
- local selectable = selectable_win_ids ()
166
- if # selectable > 0 then
167
- target_winid = selectable [1 ]
168
- else
169
- return
170
- end
176
+ target_winid = first_win_id ()
171
177
end
172
178
else
173
- local pick_window_id = pick_window ()
174
- if pick_window_id == nil then
179
+ -- pick a window
180
+ target_winid = pick_win_id ()
181
+ if target_winid == nil then
182
+ -- pick failed/cancelled
175
183
return
176
184
end
177
- target_winid = pick_window_id
178
185
end
179
186
180
187
if target_winid == - 1 then
0 commit comments