diff options
author | Guido Cella <guido@guidocella.xyz> | 2025-02-25 20:04:55 +0100 |
---|---|---|
committer | Dudemanguy <random342@airmail.cc> | 2025-03-08 19:09:23 +0000 |
commit | 3c175f01145de1ce1c3bfa0e7123236d5a7920b5 (patch) | |
tree | cab71f079fa804e9028fa3dd100e445b0839a355 /player | |
parent | c7e62ee28c206a8d8f6614a358aac4eac5850507 (diff) | |
download | mpv-3c175f01145de1ce1c3bfa0e7123236d5a7920b5.tar.bz2 mpv-3c175f01145de1ce1c3bfa0e7123236d5a7920b5.tar.xz |
console.lua: let the complete callback return a character to append
Let the complete callback return the character to append to the selected
completion.
I didn't want to document this because it's specifically meant for
properties and unlikely to be needed by other scripts, but silently
interpreting the 3rd return value can screw you over if you do something
like
return candidates, code:find('[%w_]*$')
I was doing this in my lua-repl script, and find() returns the end
position as the 2rd argument, this becomes the 3rd return value and gets
appended to completions. So you have to do
return candidates, code:find('[%w_]*$'), nil
Needed to split running commands out of console.lua.
Diffstat (limited to 'player')
-rw-r--r-- | player/javascript/defaults.js | 2 | ||||
-rw-r--r-- | player/lua/console.lua | 4 | ||||
-rw-r--r-- | player/lua/input.lua | 7 |
3 files changed, 7 insertions, 6 deletions
diff --git a/player/javascript/defaults.js b/player/javascript/defaults.js index 972f87d813..7b819f285c 100644 --- a/player/javascript/defaults.js +++ b/player/javascript/defaults.js @@ -661,7 +661,7 @@ function register_event_handler(t) { if (type == "complete" && result) { mp.commandv("script-message-to", "console", "complete", - JSON.stringify(result[0]), result[1]); + JSON.stringify(result[0]), result[1], result[2] || ""); } } diff --git a/player/lua/console.lua b/player/lua/console.lua index 22ff8b1276..3aa4c72dbd 100644 --- a/player/lua/console.lua +++ b/player/lua/console.lua @@ -2186,7 +2186,7 @@ mp.register_script_message('set-log', function (log) render() end) -mp.register_script_message('complete', function(list, start_pos) +mp.register_script_message('complete', function (list, start_pos, append) if line ~= completion_old_line or cursor ~= completion_old_cursor then return end @@ -2196,7 +2196,7 @@ mp.register_script_message('complete', function(list, start_pos) local completions = utils.parse_json(list) table.sort(completions) completion_pos = start_pos - completion_append = '' + completion_append = append for i, match in ipairs(fuzzy_find(line:sub(completion_pos, cursor), completions)) do completion_buffer[i] = completions[match[1]] diff --git a/player/lua/input.lua b/player/lua/input.lua index aadab383cc..9bbd1ca2e6 100644 --- a/player/lua/input.lua +++ b/player/lua/input.lua @@ -33,12 +33,13 @@ end local function register_event_handler(t) mp.register_script_message("input-event", function (type, args) if t[type] then - local suggestions, completion_start_position = + local completions, completion_pos, completion_append = t[type](unpack(utils.parse_json(args or "") or {})) - if type == "complete" and suggestions then + if type == "complete" and completions then mp.commandv("script-message-to", "console", "complete", - utils.format_json(suggestions), completion_start_position) + utils.format_json(completions), completion_pos, + completion_append or "") end end |