{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.
This commit is contained in:
Guido Cella
2025-02-04 10:25:42 +01:00
committed by Kacper Michajłow
parent 23e1fb472a
commit bede44618b
3 changed files with 7 additions and 9 deletions
-3
View File
@@ -664,9 +664,6 @@ function register_event_handler(t) {
JSON.stringify(result[0]), result[1]);
}
}
if (type == "closed")
mp.unregister_script_message("input-event");
})
}
+7 -2
View File
@@ -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)
-4
View File
@@ -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