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

Tweak main menu server list behavior #15736

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
27 changes: 22 additions & 5 deletions builtin/mainmenu/tab_online.lua
Original file line number Diff line number Diff line change
Expand Up @@ -391,12 +391,16 @@ local function matches_query(server, query)
return name_matches and 50 or description_matches and 0
end

local pre_search_selection = nil
y5nw marked this conversation as resolved.
Show resolved Hide resolved
siliconsniffer marked this conversation as resolved.
Show resolved Hide resolved

local function search_server_list(input)
menudata.search_result = nil
if #serverlistmgr.servers < 2 then
return
end

pre_search_selection = pre_search_selection or find_selected_server()

-- setup the search query
local query = parse_search_input(input)
if not query then
Expand All @@ -419,11 +423,23 @@ local function search_server_list(input)
return
end

local current_server = find_selected_server()

table.sort(search_result, function(a, b)
return a.points > b.points
end)
menudata.search_result = search_result

-- Keep current selection if it's in search results
if current_server then
for _, server in ipairs(search_result) do
if server.address == current_server.address and
server.port == current_server.port then
return
end
end
end

-- Find first compatible server (favorite or public)
for _, server in ipairs(search_result) do
if is_server_protocol_compat(server.proto_min, server.proto_max) then
Expand Down Expand Up @@ -484,11 +500,9 @@ local function main_button_handler(tabview, fields, name, tabdata)
if fields.btn_delete_favorite then
local idx = core.get_table_index("servers")
if not idx then return end
local server = tabdata.lookup[idx]
if not server then return end

serverlistmgr.delete_favorite(server)
set_selected_server(server)
serverlistmgr.delete_favorite(tabdata.lookup[idx])
set_selected_server(tabdata.lookup[idx+1])
return true
end

Expand Down Expand Up @@ -516,7 +530,10 @@ local function main_button_handler(tabview, fields, name, tabdata)
if fields.btn_mp_clear then
tabdata.search_for = ""
menudata.search_result = nil
set_selected_server(nil)
if pre_search_selection then
set_selected_server(pre_search_selection)
pre_search_selection = nil
end
return true
end

Expand Down
Loading