History

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.

Guido Cella committed 1 year ago

Commit 2f271a91 parent 57a6f122 files · +8 −2Browse files

Unified · Split

2 files
  1. DOCS/man/console.rst +2 −1
  2. player/lua/console.lua +6 −1
DOCS/man/console.rst+2−1
@@ -15,7 +15,8 @@ ESC and Ctrl+[ · 14 unmodified lines
15 Hide the console.15 Hide the console.
16 16
17ENTER, Ctrl+j and Ctrl+m17ENTER, Ctrl+j and Ctrl+m
18 Run the typed command.18 Expand the first completion suggestion if present and if none was selected,
19 and run the typed command.
19 20
20Shift+ENTER21Shift+ENTER
21 Type a literal newline character.22 Type a literal newline character.
player/lua/console.lua+6−1
@@ -106,6 +106,7 @@ local first_match_to_print = 1 · 105 unmodified lines
106local default_item106local default_item
107 107
108local complete108local complete
109local cycle_through_suggestions
109local set_active110local set_active
110 111
111 112
@@ -821,6 +822,10 @@ local function handle_enter() · 709 unmodified lines
821 mp.commandv('script-message-to', input_caller, 'input-event', 'submit',822 mp.commandv('script-message-to', input_caller, 'input-event', 'submit',
822 utils.format_json({line}))823 utils.format_json({line}))
823 else824 else
825 if selected_suggestion_index == 0 then
826 cycle_through_suggestions()
827 end
828
824 -- match "help [<text>]", return <text> or "", strip all whitespace829 -- match "help [<text>]", return <text> or "", strip all whitespace
825 local help = line:match('^%s*help%s+(.-)%s*$') or830 local help = line:match('^%s*help%s+(.-)%s*$') or
826 (line:match('^%s*help$') and '')831 (line:match('^%s*help$') and '')
@@ -1346,7 +1351,7 @@ local function strip_common_characters(str, prefix) · 519 unmodified lines
1346 max_overlap_length(prefix, str)))1351 max_overlap_length(prefix, str)))
1347end1352end
1348 1353
1349local function cycle_through_suggestions(backwards)1354cycle_through_suggestions = function (backwards)
1350 if #suggestion_buffer == 0 then1355 if #suggestion_buffer == 0 then
1351 -- Allow Tab completion of commands before typing anything.1356 -- Allow Tab completion of commands before typing anything.
1352 if line == '' then1357 if line == '' then

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t