From 8cd366c6aa105016dee10e73ecc1b0a5f1f2f84d Mon Sep 17 00:00:00 2001 From: Guido Cella Date: Sun, 24 Nov 2024 10:45:42 +0100 Subject: [PATCH 1/2] console.lua: save commands in history after autocompletion 2f271a92de made it so that the first completion suggestion is automatically selected when pressing enter, but that was done after saving the command in the history. Save it to the history after expanding it, so re-running the previous command actually works, e.g. save "set vo gpu-next" instead of "set vo gn". --- player/lua/console.lua | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/player/lua/console.lua b/player/lua/console.lua index 4db8df20a1e8e..4d5bfcd83fae2 100644 --- a/player/lua/console.lua +++ b/player/lua/console.lua @@ -808,9 +808,6 @@ local function handle_enter() if line == '' and input_caller == nil then return end - if history[#history] ~= line and line ~= '' then - history_add(line) - end if selectable_items then if #matches > 0 then @@ -836,6 +833,10 @@ local function handle_enter() end end + if history[#history] ~= line and line ~= '' then + history_add(line) + end + clear() end From 5c04d3c3f7af44b5d3046e8ec7fbca783baf26ce Mon Sep 17 00:00:00 2001 From: Guido Cella Date: Sun, 24 Nov 2024 11:10:08 +0100 Subject: [PATCH 2/2] console.lua: highlight the first completion suggestion before cycling 2f271a92de made it so that the first completion suggestion is automatically selected when pressing Enter, if none was manually selected. So automatically highlight the first completion in yellow to show this. --- player/lua/console.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/player/lua/console.lua b/player/lua/console.lua index 4d5bfcd83fae2..8b4bdf0f73e06 100644 --- a/player/lua/console.lua +++ b/player/lua/console.lua @@ -367,7 +367,8 @@ local function format_table(list, width_max, rows_max) or '%-' .. math.min(column_widths[column], 99) .. 's' columns[column] = ass_escape(string.format(format_string, list[i])) - if i == selected_suggestion_index then + if i == selected_suggestion_index or + (i == 1 and selected_suggestion_index == 0) then columns[column] = styles.selected_suggestion .. columns[column] .. '{\\b0}'.. styles.suggestion end