From bede44618b187c22306e49f3664c5dac162cf734 Mon Sep 17 00:00:00 2001 From: Guido Cella Date: Tue, 4 Feb 2025 10:25:42 +0100 Subject: [PATCH] {console,input}.lua: allow subsequent mp.input calls Currently using mp.input while the console is open doesn't do anything. We can allow using mp.input multiple times in a row by keeping the console open, and sending a closed event only when the previous calling script is different from the current one. If it is the same, sending a closed event would unregister the new input-event listener, so it is just never sent in this case as there is no sane way to do it. This is useful e.g. to try out select script bindings in the console, or to switch to a different mp.input script binding with a key binding without having to close the current one. Calling input.select() again within input.select()'s submit handler needs to be fixed separately because with select the console is immediately closed on submit (367a6b561a), so input.lua receives submit, requests a new selection, and receives closed wich unregisters the handler of the new selection. Just not calling mp.unregister_script_message("input-event") fixes it; its only purpose was to allow garbage collection of variables defined in the scope using mp.input. Fixes #15795. --- player/javascript/defaults.js | 3 --- player/lua/console.lua | 9 +++++++-- player/lua/input.lua | 4 ---- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/player/javascript/defaults.js b/player/javascript/defaults.js index 972f87d813..6ac5b5e9ee 100644 --- a/player/javascript/defaults.js +++ b/player/javascript/defaults.js @@ -664,9 +664,6 @@ function register_event_handler(t) { JSON.stringify(result[0]), result[1]); } } - - if (type == "closed") - mp.unregister_script_message("input-event"); }) } diff --git a/player/lua/console.lua b/player/lua/console.lua index 027d1f1869..ec9fa55bfd 100644 --- a/player/lua/console.lua +++ b/player/lua/console.lua @@ -1839,8 +1839,9 @@ mp.register_script_message('type', function(text, cursor_pos) end) mp.register_script_message('get-input', function (script_name, args) - if repl_active then - return + if repl_active and input_caller and script_name ~= input_caller then + mp.commandv('script-message-to', input_caller, 'input-event', + 'closed', utils.format_json({line, cursor})) end input_caller = script_name @@ -1856,6 +1857,7 @@ mp.register_script_message('get-input', function (script_name, args) end history = histories[id] history_pos = #history + 1 + searching_history = false if args.items then selectable_items = {} @@ -1865,6 +1867,9 @@ mp.register_script_message('get-input', function (script_name, args) default_item = args.default_item handle_edit() bind_mouse() + else + selectable_items = nil + unbind_mouse() end set_active(true) diff --git a/player/lua/input.lua b/player/lua/input.lua index aadab383cc..196d61213b 100644 --- a/player/lua/input.lua +++ b/player/lua/input.lua @@ -41,10 +41,6 @@ local function register_event_handler(t) utils.format_json(suggestions), completion_start_position) end end - - if type == "closed" then - mp.unregister_script_message("input-event") - end end) end