Skip to content

Commit

Permalink
console.lua: expand the first completion on Enter
Browse files Browse the repository at this point in the history
If you run a command without manually selecting a completion, select the
first one. e.g. set vo gn runs set vo gpu-next.
  • Loading branch information
guidocella authored and kasper93 committed Nov 23, 2024
1 parent 57a6f12 commit 2f271a9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
3 changes: 2 additions & 1 deletion DOCS/man/console.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
7 changes: 6 additions & 1 deletion player/lua/console.lua
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ local first_match_to_print = 1
local default_item

local complete
local cycle_through_suggestions
local set_active


Expand Down Expand Up @@ -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 [<text>]", return <text> or "", strip all whitespace
local help = line:match('^%s*help%s+(.-)%s*$') or
(line:match('^%s*help$') and '')
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 2f271a9

Please sign in to comment.