Skip to content

Commit 0417218

Browse files
guidocellakasper93
authored andcommitted
console.lua: don't highlight the first completion with mp.input.get
The first completion is highlighted because it is automatically inserted when pressing Enter, but this isn't the case when the console is used with mp.input.get, and autoselecting it can be undesirable if you're entering arbitrary text, unlike with mpv commands where you're usually choosing from predefined lists. So just don't highlight the first completion for mp.input clients.
1 parent 4dbf81c commit 0417218

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

player/lua/console.lua

+7-4
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,11 @@ local function calculate_max_log_lines()
296296
- 1.5)
297297
end
298298

299+
local function should_highlight_completion(i)
300+
return i == selected_suggestion_index or
301+
(i == 1 and selected_suggestion_index == 0 and input_caller == nil)
302+
end
303+
299304
-- Takes a list of strings, a max width in characters and
300305
-- optionally a max row count.
301306
-- The result contains at least one column.
@@ -377,8 +382,7 @@ local function format_table(list, width_max, rows_max)
377382
or '%-' .. math.min(column_widths[column], 99) .. 's'
378383
columns[column] = ass_escape(string.format(format_string, list[i]))
379384

380-
if i == selected_suggestion_index or
381-
(i == 1 and selected_suggestion_index == 0) then
385+
if should_highlight_completion(i) then
382386
columns[column] = styles.selected_suggestion .. columns[column]
383387
.. '{\\b}' .. styles.suggestion
384388
end
@@ -491,8 +495,7 @@ local function print_to_terminal()
491495

492496
local suggestions = ''
493497
for i, suggestion in ipairs(suggestion_buffer) do
494-
if i == selected_suggestion_index or
495-
(i == 1 and selected_suggestion_index == 0) then
498+
if should_highlight_completion(i) then
496499
suggestions = suggestions .. terminal_styles.selected_suggestion ..
497500
suggestion .. '\027[0m'
498501
else

0 commit comments

Comments
 (0)