diff --git a/.luacheckrc b/.luacheckrc index dda48b031d23b..d096c1c368391 100644 --- a/.luacheckrc +++ b/.luacheckrc @@ -57,6 +57,7 @@ local mp_globals = { disable_key_bindings = {}, enable_key_bindings = {}, find_config_file = {}, + flush_keybindings = {}, format_time = {}, get_mouse_pos = {}, set_key_bindings = {}, @@ -78,7 +79,6 @@ local mp_internal = { UNKNOWN_TYPE = { fields = { info = {}, type = {} }}, _legacy_overlay = { fields = { res_x = {}, res_y = {}, data = {}, update = {} }}, cancel_timer = {}, - flush_keybindings = {}, get_osd_margins = {}, input_define_section = {}, input_disable_section = {}, diff --git a/DOCS/man/lua.rst b/DOCS/man/lua.rst index 2ce63ce671653..631ffd97c822c 100644 --- a/DOCS/man/lua.rst +++ b/DOCS/man/lua.rst @@ -938,7 +938,7 @@ REPL. ``opened`` A callback invoked when the console is shown. This can be used to - present a list of options with ``input.set_log()``. + override keybinds set by the console with ``mp.add_forced_key_binding()``. ``edited`` A callback invoked when the text changes. The first argument is the text diff --git a/player/lua/console.lua b/player/lua/console.lua index d2bf222acb40e..cd753db122250 100644 --- a/player/lua/console.lua +++ b/player/lua/console.lua @@ -93,7 +93,6 @@ local MAX_LOG_LINES = 10000 local log_buffers = {} local log_offset = 0 local key_bindings = {} -local dont_bind_up_down = false local global_margins = { t = 0, b = 0 } local input_caller local input_caller_handler @@ -1573,12 +1572,10 @@ local function define_key_bindings() return end 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. - 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 + -- 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 mp.add_forced_key_binding("any_unicode", "_console_text", text_input, {repeatable = true, complex = true}) @@ -1683,7 +1680,6 @@ mp.register_script_message("get-input", function (args) keep_open = args.keep_open default_item = args.default_item has_completions = args.has_completions - dont_bind_up_down = args.dont_bind_up_down searching_history = false if args.items then @@ -1736,6 +1732,10 @@ mp.register_script_message("get-input", function (args) end set_active(true) + + -- We want to ensure the keybindings have been set before sending the "opened" event + -- in case scripts want to override our bindings. + mp.flush_keybindings() mp.commandv("script-message-to", input_caller, input_caller_handler, "opened") end) diff --git a/player/lua/stats.lua b/player/lua/stats.lua index dcb78501cb93a..408b5706c4e15 100644 --- a/player/lua/stats.lua +++ b/player/lua/stats.lua @@ -1579,6 +1579,9 @@ local function unbind_scroll() end end +local add_page_bindings +local remove_page_bindings + local function filter_bindings() input.get({ prompt = "Filter bindings:", @@ -1586,6 +1589,10 @@ local function filter_bindings() -- This is necessary to close the console if the oneshot -- display_timer expires without typing anything. searched_text = "" + + -- Must be re-bound to override the console.lua bindings. + remove_page_bindings() + bind_scroll() end, edited = function (text) reset_scroll_offsets() @@ -1599,6 +1606,7 @@ local function filter_bindings() closed = function () searched_text = nil if display_timer:is_enabled() then + add_page_bindings() print_page(curr_page) if display_timer.oneshot then display_timer:kill() @@ -1606,7 +1614,6 @@ local function filter_bindings() end end end, - dont_bind_up_down = true, }) end @@ -1648,7 +1655,7 @@ local function update_scroll_bindings(k) end -- Add keybindings for every page -local function add_page_bindings() +add_page_bindings = function() local function a(k) return function() reset_scroll_offsets() @@ -1667,7 +1674,7 @@ end -- Remove keybindings for every page -local function remove_page_bindings() +remove_page_bindings = function() for k, _ in pairs(pages) do mp.remove_key_binding("__forced_"..k) end