From 22135fff7cbb83c4f6cdaf787b55c61f404b72d2 Mon Sep 17 00:00:00 2001 From: David Vazgenovich Shakaryan Date: Tue, 6 Jan 2026 21:31:57 -0800 Subject: avoid changing favourites menu order when possible --- main.lua | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/main.lua b/main.lua index 0ed84b5..ffb7707 100644 --- a/main.lua +++ b/main.lua @@ -472,6 +472,12 @@ local function set_menu_sort(menu, bool) menu.sorted = bool end +-- refresh options when navigating up the stack to a previous favourites menu. +-- existing menu options are never removed, even if unfavourited. if the order +-- of still-favourited items is unchanged and no new favourites have been added +-- before the last still-favourited item, the existing order is kept and all +-- new favourites are appended to the end of the menu. otherwise, the new order +-- is used and any unfavourited options are moved to the end. local function refresh_favourites_menu() local menu = menus[depth] local opt = menu.options[menu.cursor] @@ -485,12 +491,32 @@ local function refresh_favourites_menu() for _, v in ipairs(options) do seen[v.id] = true end + + local same = true + local ind = 1 for _, v in ipairs(menu.options) do - if not seen[v.id] then - options[#options+1] = v + if seen[v.id] then + if v.id == options[ind].id then + ind = ind + 1 + else + same = false + break + end end end - menu.options = options + + if same then + for i = ind, #options do + menu.options[#menu.options+1] = options[i] + end + else + for _, v in ipairs(menu.options) do + if not seen[v.id] then + options[#options+1] = v + end + end + menu.options = options + end if sorted then set_menu_sort(menu, true) -- cgit v1.2.3-70-g09d2