Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 additions & 4 deletions lua/window-picker/hints/floating-big-letter-hint.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ local border = {
{ '│', 'FloatBorder' },
}

function M:new()
function M:new(config)
local o = {
win = {
width = 18,
Expand All @@ -35,6 +35,7 @@ function M:new()

setmetatable(o, M)
self.__index = self
self.config = config

return o
end
Expand All @@ -47,7 +48,7 @@ function M:set_config(config)
self.big_chars = require(('window-picker.hints.data.%s'):format(font))
end

if type(font) == 'table' then
if type(font) == 'table' then
self.big_chars = font
end
end
Expand Down Expand Up @@ -123,12 +124,29 @@ function M:_show_letter_in_window(window, char)
end

function M:draw(windows)
for index, window in ipairs(windows) do
local char = self.chars[index]
local windowlist = {}
for _, win in ipairs(windows) do
windowlist[win] = false
end
if self.config.pre_assign_chars then
windowlist = self.config.pre_assign_chars(windowlist)
end

local _idx = 1
for _win, _char in pairs(windowlist) do
local window = _win
local char = _char
if not char then
char = self.chars[_idx]
windowlist[_win] = char
_idx = _idx + 1
end
local big_char = self.big_chars[char:lower()]
local window_id = self:_show_letter_in_window(window, big_char)
table.insert(self.windows, window_id)
end

return windowlist
end

function M:clear()
Expand Down
5 changes: 3 additions & 2 deletions lua/window-picker/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ function M.pick_window(custom_config)
return builder
:new()
:set_config(custom_config)
:set_hint(FloatingHint:new())
:set_hint(FloatingHint:new(custom_config.hint))
:set_picker()
:set_filter()
:build()
:pick_window()
end

function M.setup() end
function M.setup()
end

return M
14 changes: 12 additions & 2 deletions lua/window-picker/pickers/window-picker.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ end

function M:set_config(config)
self.chars = config.chars
self.process_unknown_char = config.process_unknown_char
self.show_prompt = config.show_prompt
self.prompt_message = config.prompt_message
self.autoselect_one = config.filter_rules.autoselect_one
Expand Down Expand Up @@ -60,7 +61,7 @@ function M:pick_window()

local window = nil

self.hint:draw(windows)
local windowlist = self.hint:draw(windows)

vim.cmd.redraw()

Expand All @@ -75,7 +76,16 @@ function M:pick_window()
self.hint:clear()

if char then
window = self:_find_matching_win_for_char(char, windows)
for w, c in pairs(windowlist) do
if c == (char:upper()) then
window = w
end
end
-- window = self:_find_matching_win_for_char(char, windows) or char
end

if not window and self.process_unknown_char then
window = self.process_unknown_char(char, windowlist)
end

return window
Expand Down