diff options
| author | David Vazgenovich Shakaryan <dvshakaryan@gmail.com> | 2026-01-07 00:13:04 -0800 |
|---|---|---|
| committer | David Vazgenovich Shakaryan <dvshakaryan@gmail.com> | 2026-01-07 00:13:04 -0800 |
| commit | 0eb133c814538f000a8416880383aa4468b919c3 (patch) | |
| tree | d03d700bd664fd88f2c5d8ca09ab371240449f30 | |
| parent | 22135fff7cbb83c4f6cdaf787b55c61f404b72d2 (diff) | |
| download | mpv-iptv-menu-0eb133c814538f000a8416880383aa4468b919c3.tar.gz mpv-iptv-menu-0eb133c814538f000a8416880383aa4468b919c3.tar.xz | |
improved merge on favourites refresh
| -rw-r--r-- | main.lua | 46 |
1 files changed, 21 insertions, 25 deletions
@@ -473,11 +473,9 @@ local function set_menu_sort(menu, 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. +-- existing menu options are never removed, even if unfavourited. the new order +-- is always respected, while still preserving the relative order of existing +-- options when possible. local function refresh_favourites_menu() local menu = menus[depth] local opt = menu.options[menu.cursor] @@ -487,36 +485,34 @@ local function refresh_favourites_menu() end local options = group_menu_options(catalogue:get(menu.group_id)) + local pos = {} + for i, v in ipairs(options) do + pos[v.id] = i + end + + local res = {} local seen = {} - for _, v in ipairs(options) do - seen[v.id] = true + local function append(v) + if not seen[v.id] then + res[#res+1] = v + seen[v.id] = true + end end - local same = true local ind = 1 for _, v in ipairs(menu.options) do - if seen[v.id] then - if v.id == options[ind].id then + if pos[v.id] then + while ind <= pos[v.id] do + append(options[ind]) ind = ind + 1 - else - same = false - break end end + append(v) end - - 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 + for i = ind, #options do + append(options[i]) end + menu.options = res if sorted then set_menu_sort(menu, true) |
