mirror of
https://github.com/mpv-player/mpv.git
synced 2026-10-28 06:16:38 +08:00
mp.input: avoid displaying outdated completions from the same client
Previously, completion responses from the same client would be displayed even if the user had since changed the input, as long as a newer complete event had already been sent. This meant that, if clients took a sufficiently long time to return completions, then console.lua would display completions for previous versions of the line which were no longer valid. This commit has the client send back the version of the line their completions apply to, ensuring that `console.lua` displays the correct completions.
This commit is contained in:
committed by
Kacper Michajłow
parent
c568e1539f
commit
5a1700a456
@@ -678,6 +678,7 @@ function register_event_handler(t) {
|
||||
mp.commandv("script-message-to", "console", "complete", JSON.stringify({
|
||||
client_name: mp.script_name,
|
||||
handler_id: handler_id,
|
||||
original_line: args[0],
|
||||
list: completions,
|
||||
start_pos: completion_pos,
|
||||
append: completion_append || "",
|
||||
|
||||
@@ -102,8 +102,6 @@ local completion_buffer = {}
|
||||
local selected_completion_index
|
||||
local completion_pos
|
||||
local completion_append
|
||||
local completion_old_line
|
||||
local completion_old_cursor
|
||||
local autoselect_completion
|
||||
local has_completions
|
||||
|
||||
@@ -1480,8 +1478,6 @@ end
|
||||
|
||||
-- Show autocompletions.
|
||||
complete = function ()
|
||||
completion_old_line = line
|
||||
completion_old_cursor = cursor
|
||||
mp.commandv("script-message-to", input_caller, input_caller_handler,
|
||||
"complete", utils.format_json({line:sub(1, cursor - 1)}))
|
||||
render()
|
||||
@@ -1802,7 +1798,7 @@ mp.register_script_message("complete", function (message)
|
||||
message = utils.parse_json(message)
|
||||
|
||||
if message.client_name ~= input_caller or message.handler_id ~= input_caller_handler
|
||||
or line ~= completion_old_line or cursor ~= completion_old_cursor then
|
||||
or line:sub(1, cursor - 1) ~= message.original_line then
|
||||
return
|
||||
end
|
||||
|
||||
|
||||
@@ -60,6 +60,7 @@ local function register_event_handler(t)
|
||||
mp.commandv("script-message-to", "console", "complete", utils.format_json({
|
||||
client_name = mp.get_script_name(),
|
||||
handler_id = handler_id,
|
||||
original_line = args[1],
|
||||
list = completions,
|
||||
start_pos = completion_pos,
|
||||
append = completion_append or "",
|
||||
|
||||
Reference in New Issue
Block a user