Skip to content

Commit bed6555

Browse files
committed
fix: Not enough space when trying to set winbar
1 parent d645ac7 commit bed6555

File tree

3 files changed

+35
-5
lines changed

3 files changed

+35
-5
lines changed

lua/window-picker/hints/statusline-hint.lua

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,13 @@ function M:draw(windows)
6969
for index, window in ipairs(windows) do
7070
local char = self.chars[index]
7171

72-
vim.wo[window].statusline = self.selection_display
72+
73+
local display_text = self.selection_display
7374
and self.selection_display(char, window)
7475
or '%=' .. char .. '%='
7576

77+
vim.wo[window].statusline = display_text
78+
7679
vim.wo[window].winhl =
7780
'StatusLine:WindowPickerStatusLine,StatusLineNC:WindowPickerStatusLineNC'
7881
end
@@ -84,7 +87,7 @@ end
8487
function M:clear()
8588
for window, options in pairs(self.window_options) do
8689
for opt_key, opt_value in pairs(options) do
87-
vim.wo[window][opt_key] = opt_value
90+
pcall(vim.api.nvim_win_set_option, window, opt_key, opt_value)
8891
end
8992
end
9093

lua/window-picker/hints/statusline-winbar-hint.lua

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,18 +72,44 @@ function M:draw(windows)
7272

7373
for index, window in ipairs(windows) do
7474
local char = self.chars[index]
75-
76-
vim.wo[window][indicator_setting] = self.selection_display
75+
local display_text = self.selection_display
7776
and self.selection_display(char, window)
7877
or '%=' .. char .. '%='
7978

80-
vim.wo[window].winhl = string.format(
79+
local winhl = string.format(
8180
'%s:WindowPicker%s,%sNC:WindowPicker%sNC',
8281
indicator_hl,
8382
indicator_hl,
8483
indicator_hl,
8584
indicator_hl
8685
)
86+
87+
local ok, result = pcall(
88+
vim.api.nvim_win_set_option,
89+
window,
90+
indicator_setting,
91+
display_text
92+
)
93+
94+
if not ok then
95+
local buffer = vim.api.nvim_win_get_buf(window)
96+
local message = 'Unable to set '
97+
.. indicator_setting
98+
.. ' for window id::'
99+
.. window
100+
.. '\n'
101+
.. 'filetype::'
102+
.. vim.bo[buffer]['filetype']
103+
.. '\n'
104+
.. 'consider ignoring unwanted windows using filter options\n'
105+
.. 'actual error\n'
106+
.. result
107+
108+
vim.notify(message, vim.log.levels.WARN)
109+
end
110+
111+
-- pcall(vim.api.nvim_win_set_option, window, 'winhl', winhl)
112+
vim.wo[window]['winhl'] = winhl
87113
end
88114

89115
vim.cmd.redraw()

lua/window-picker/util.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ local M = {}
33
function M.escape_pattern(text)
44
return text:gsub('([^%w])', '%%%1')
55
end
6+
67
function M.tbl_filter(tbl, filter_func)
78
return vim.tbl_filter(filter_func, tbl)
89
end

0 commit comments

Comments
 (0)