stats.lua: scroll keybindings while filtering them

console.lua binds up and down to navigate its history. Add a private
flag to mp.input.get to instruct console.lua not to bind up and down, so
you can use them to scroll the keybindings page while filtering
keybindings.

If it is requested, this can be replaced with an argument to input.get
to not bind arbitrary keys.

Fixes #14966.
This commit is contained in:
Guido Cella 2024-10-01 20:53:47 +02:00 committed by Avi Halachmi
parent b3f8464fa9
commit be814e3753
2 changed files with 10 additions and 4 deletions

View File

@ -93,6 +93,7 @@ local history_pos = 1
local searching_history = false
local log_buffers = {[id] = {}}
local key_bindings = {}
local dont_bind_up_down = false
local global_margins = { t = 0, b = 0 }
local input_caller
@ -1624,10 +1625,12 @@ local function define_key_bindings()
return
end
for _, bind in ipairs(get_bindings()) do
-- Generate arbitrary name for removing the bindings later.
local name = "_console_" .. (#key_bindings + 1)
key_bindings[#key_bindings + 1] = name
mp.add_forced_key_binding(bind[1], name, bind[2], {repeatable = true})
if not (dont_bind_up_down and (bind[1] == 'up' or bind[1] == 'down')) then
-- Generate arbitrary name for removing the bindings later.
local name = "_console_" .. (#key_bindings + 1)
key_bindings[#key_bindings + 1] = name
mp.add_forced_key_binding(bind[1], name, bind[2], {repeatable = true})
end
end
mp.add_forced_key_binding("any_unicode", "_console_text", text_input,
{repeatable = true, complex = true})
@ -1675,6 +1678,7 @@ set_active = function (active)
line = ''
cursor = 1
selectable_items = nil
dont_bind_up_down = false
end
collectgarbage()
end
@ -1734,6 +1738,7 @@ mp.register_script_message('get-input', function (script_name, args)
line = args.default_text or ''
cursor = args.cursor_position or line:len() + 1
id = args.id or script_name .. prompt
dont_bind_up_down = args.dont_bind_up_down
if histories[id] == nil then
histories[id] = {}
log_buffers[id] = {}

View File

@ -1619,6 +1619,7 @@ local function filter_bindings()
end
end
end,
dont_bind_up_down = true,
})
end