Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

console.lua: focus the default item after emptying the input line #15617

Merged
merged 2 commits into from
Jan 3, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 13 additions & 12 deletions player/lua/console.lua
Original file line number Diff line number Diff line change
Expand Up @@ -689,12 +689,22 @@ end
local function handle_edit()
if selectable_items then
matches = {}
selected_match = 1

for i, match in ipairs(fuzzy_find(line, selectable_items)) do
matches[i] = { index = match, text = selectable_items[match] }
end

if line == '' and default_item then
selected_match = default_item

local max_lines = calculate_max_log_lines()
first_match_to_print = math.max(1, selected_match - math.floor(max_lines / 2) + 1)
if first_match_to_print > #selectable_items - max_lines + 2 then
first_match_to_print = math.max(1, #selectable_items - max_lines + 1)
end
else
selected_match = 1
end

update()

return
Expand Down Expand Up @@ -1023,7 +1033,6 @@ local function search_history()
searching_history = true
suggestion_buffer = {}
selectable_items = {}
first_match_to_print = 1

for i = 1, #history do
selectable_items[i] = history[#history + 1 - i]
Expand Down Expand Up @@ -1820,16 +1829,8 @@ mp.register_script_message('get-input', function (script_name, args)
for i, item in ipairs(args.items) do
selectable_items[i] = item:gsub("[\r\n].*", "⋯"):sub(1, 300)
end
handle_edit()
selected_match = args.default_item or 1
default_item = args.default_item

local max_lines = calculate_max_log_lines()
first_match_to_print = math.max(1, selected_match - math.floor(max_lines / 2) + 1)
if first_match_to_print > #selectable_items - max_lines + 2 then
first_match_to_print = math.max(1, #selectable_items - max_lines + 1)
end

handle_edit()
bind_mouse()
end

Expand Down
Loading