Skip to content
Merged
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
2 changes: 1 addition & 1 deletion .luacheckrc
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {},
Expand All @@ -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 = {},
Expand Down
2 changes: 1 addition & 1 deletion DOCS/man/lua.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 8 additions & 8 deletions player/lua/console.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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})
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down
13 changes: 10 additions & 3 deletions player/lua/stats.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1579,13 +1579,20 @@ local function unbind_scroll()
end
end

local add_page_bindings
local remove_page_bindings

local function filter_bindings()
input.get({
prompt = "Filter bindings:",
opened = function ()
-- 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()
Expand All @@ -1599,14 +1606,14 @@ 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()
display_timer:resume()
end
end
end,
dont_bind_up_down = true,
})
end

Expand Down Expand Up @@ -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()
Expand All @@ -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
Expand Down