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

View File

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