From 2f271a92decd2212bb773dc7027f8e2fa6db9010 Mon Sep 17 00:00:00 2001 From: Guido Cella Date: Sat, 23 Nov 2024 09:14:18 +0100 Subject: [PATCH] console.lua: expand the first completion on Enter If you run a command without manually selecting a completion, select the first one. e.g. set vo gn runs set vo gpu-next. --- DOCS/man/console.rst | 3 ++- player/lua/console.lua | 7 ++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/DOCS/man/console.rst b/DOCS/man/console.rst index 24b52fd5d3366..28c868dd92d0a 100644 --- a/DOCS/man/console.rst +++ b/DOCS/man/console.rst @@ -15,7 +15,8 @@ ESC and Ctrl+[ Hide the console. ENTER, Ctrl+j and Ctrl+m - Run the typed command. + Expand the first completion suggestion if present and if none was selected, + and run the typed command. Shift+ENTER Type a literal newline character. diff --git a/player/lua/console.lua b/player/lua/console.lua index a4e2a38bdb7d6..4db8df20a1e8e 100644 --- a/player/lua/console.lua +++ b/player/lua/console.lua @@ -106,6 +106,7 @@ local first_match_to_print = 1 local default_item local complete +local cycle_through_suggestions local set_active @@ -821,6 +822,10 @@ local function handle_enter() mp.commandv('script-message-to', input_caller, 'input-event', 'submit', utils.format_json({line})) else + if selected_suggestion_index == 0 then + cycle_through_suggestions() + end + -- match "help []", return or "", strip all whitespace local help = line:match('^%s*help%s+(.-)%s*$') or (line:match('^%s*help$') and '') @@ -1346,7 +1351,7 @@ local function strip_common_characters(str, prefix) max_overlap_length(prefix, str))) end -local function cycle_through_suggestions(backwards) +cycle_through_suggestions = function (backwards) if #suggestion_buffer == 0 then -- Allow Tab completion of commands before typing anything. if line == '' then