Skip to content

Commit b9ceaf2

Browse files
guidocellasfan5
authored andcommitted
console.lua: don't autoselect the wrong completion
The first completion is automatically inserted when Tab was not pressed, but this is unwanted when you already typed one of the completions which is not the first one, move back the cursor and press Enter. e.g. if the line is "set vid", you place the cursor before "v" and press Enter, it runs "set ab-loop-avid". Fix this by aborting when the text in front of the cursor matches one of the completions.
1 parent 6269f4f commit b9ceaf2

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

player/lua/console.lua

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1031,6 +1031,16 @@ local function unbind_mouse()
10311031
mp.remove_key_binding("_console_mbtn_left")
10321032
end
10331033

1034+
local function after_cur_matches_completion()
1035+
local token = line:sub(completion_pos)
1036+
1037+
for _, completion in pairs(completion_buffer) do
1038+
if completion == token:sub(1, #completion) then
1039+
return true
1040+
end
1041+
end
1042+
end
1043+
10341044
-- Run the current command or select the current item
10351045
local function submit()
10361046
if searching_history then
@@ -1049,7 +1059,8 @@ local function submit()
10491059
utils.format_json({matches[focused_match].index}))
10501060
end
10511061
else
1052-
if selected_completion_index == 0 and autoselect_completion then
1062+
if selected_completion_index == 0 and autoselect_completion
1063+
and not after_cur_matches_completion() then
10531064
cycle_through_completions()
10541065
end
10551066

0 commit comments

Comments
 (0)