From 661bd61af8d312ed357a52d47f6a88f58b5af8fd Mon Sep 17 00:00:00 2001 From: Guido Cella Date: Wed, 9 Oct 2024 22:09:19 +0200 Subject: [PATCH] console.lua: center selectable items around the default item --- player/lua/console.lua | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/player/lua/console.lua b/player/lua/console.lua index f13656a6b4..62180eb303 100644 --- a/player/lua/console.lua +++ b/player/lua/console.lua @@ -1787,7 +1787,13 @@ mp.register_script_message('get-input', function (script_name, args) matches = {} selected_match = args.default_item or 1 default_item = args.default_item - first_match_to_print = 1 + + local max_lines = calculate_max_log_lines() + first_match_to_print = math.max(1, selected_match - math.floor(max_lines / 2) + 2) + if first_match_to_print > #selectable_items - max_lines + 2 then + first_match_to_print = math.max(1, #selectable_items - max_lines + 2) + end + for i, item in ipairs(selectable_items) do matches[i] = { index = i, text = item } end