Skip to content

Commit 9e88474

Browse files
committed
refactor: Simplify window picker UI logic.
1 parent 964e428 commit 9e88474

File tree

1 file changed

+11
-18
lines changed

1 file changed

+11
-18
lines changed

lua/winshift/lib.lua

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -346,25 +346,20 @@ function M.pick_window(opt)
346346
-- Setup UI
347347
for _, id in ipairs(selectable) do
348348
local char = chars:sub(i, i)
349-
local ok_status, statusline = pcall(api.nvim_win_get_option, id, "statusline")
350-
local ok_hl, winhl = pcall(api.nvim_win_get_option, id, "winhl")
351349

350+
win_map[char] = id
352351
win_opts[id] = {
353-
statusline = ok_status and statusline or "",
354-
winhl = ok_hl and winhl or ""
352+
statusline = vim.wo[id].statusline,
353+
winhl = vim.wo[id].winhl,
355354
}
356-
win_map[char] = id
357355

358-
utils.set_local(
359-
id,
360-
{
361-
statusline = "%=" .. char .. "%=",
362-
winhl = {
363-
"StatusLine:WinShiftWindowPicker,StatusLineNC:WinShiftWindowPicker",
364-
opt = { method = "append" },
365-
},
366-
}
367-
)
356+
utils.set_local(id, {
357+
statusline = "%=" .. char .. "%=",
358+
winhl = {
359+
"StatusLine:WinShiftWindowPicker,StatusLineNC:WinShiftWindowPicker",
360+
opt = { method = "append" },
361+
},
362+
})
368363

369364
i = i + 1
370365
if i > #chars then break end
@@ -379,9 +374,7 @@ function M.pick_window(opt)
379374

380375
-- Restore window options
381376
for _, id in ipairs(selectable) do
382-
for option, value in pairs(win_opts[id]) do
383-
api.nvim_win_set_option(id, option, value)
384-
end
377+
utils.set_local(id, win_opts[id])
385378
end
386379

387380
vim.o.laststatus = laststatus

0 commit comments

Comments
 (0)