diff options
| author | David Vazgenovich Shakaryan <dvshakaryan@gmail.com> | 2026-01-06 21:31:57 -0800 |
|---|---|---|
| committer | David Vazgenovich Shakaryan <dvshakaryan@gmail.com> | 2026-01-06 21:31:57 -0800 |
| commit | 22135fff7cbb83c4f6cdaf787b55c61f404b72d2 (patch) | |
| tree | 138eb7e935e9ba88d1f1aab25a1453704c6e41e1 | |
| parent | 8d9e9e400232e26ed27e00adab96caec06074be2 (diff) | |
| download | mpv-iptv-menu-22135fff7cbb83c4f6cdaf787b55c61f404b72d2.tar.gz mpv-iptv-menu-22135fff7cbb83c4f6cdaf787b55c61f404b72d2.tar.xz | |
avoid changing favourites menu order when possible
| -rw-r--r-- | main.lua | 32 |
1 files changed, 29 insertions, 3 deletions
@@ -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) |
