summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Vazgenovich Shakaryan <dvshakaryan@gmail.com>2026-02-06 17:43:10 -0800
committerDavid Vazgenovich Shakaryan <dvshakaryan@gmail.com>2026-02-06 17:43:10 -0800
commit0cc08ff142621dac444d84be05bf9b6f4acd602b (patch)
tree41b1b716c555efa5da8363077affd47ee2edc62b
parent1d93ccb330dca438322a0438b79eea718c4cf73b (diff)
downloadmpv-iptv-menu-0cc08ff142621dac444d84be05bf9b6f4acd602b.tar.gz
mpv-iptv-menu-0cc08ff142621dac444d84be05bf9b6f4acd602b.tar.xz
allow teleporting back after a gotoHEADmaster
-rw-r--r--main.lua1
-rw-r--r--rt.lua41
-rw-r--r--state.lua24
3 files changed, 56 insertions, 10 deletions
diff --git a/main.lua b/main.lua
index 67a195d..ab14744 100644
--- a/main.lua
+++ b/main.lua
@@ -128,6 +128,7 @@ input.set_persistent_mapping({
})
input.define_mapping('MENU', {
['BS'] = {rt.prev_menu},
+ ['Ctrl+BS'] = {rt.goto_origin},
['/'] = {rt.start_search},
['E'] = {rt.start_epg_search},
['Ctrl+s'] = {rt.toggle_menu_sort},
diff --git a/rt.lua b/rt.lua
index 73b5b9d..f5a47ac 100644
--- a/rt.lua
+++ b/rt.lua
@@ -578,7 +578,7 @@ function rt.open_option_info(opt)
end
end
-local function goto_path(path, opt, reverse)
+local function goto_path_traverse(path, opt, reverse)
local start, stop, step = 1, #path, 1
if reverse then
start, stop, step = stop, start, -1
@@ -596,6 +596,14 @@ local function goto_path(path, opt, reverse)
cursor_to_id(opt.id)
end
+local function goto_path(d, ...)
+ local origin = state:capture_origin(d)
+ state.depth = d
+ goto_path_traverse(...)
+ state:menu().origin = origin
+ osd:dirty()
+end
+
function rt.goto_option()
local menu = state:menu()
local opt = menu.options[menu.cursor]
@@ -603,17 +611,17 @@ function rt.goto_option()
return
end
+ local d = state.depth
if menu.group_id == 'favourites' then
- state.depth = 1
+ d = 1
elseif menu.type == 'search' then
- state.depth = state.depth - 1
- if state:menu().group_id == 'favourites' then
- merge_refreshed_menu_options()
- end
+ d = d - 1
end
- goto_path(opt.path, opt)
- osd:dirty()
+ goto_path(d, opt.path, opt)
+ if state:menu().group_id == 'favourites' then
+ merge_refreshed_menu_options()
+ end
end
function rt.goto_playing()
@@ -624,8 +632,21 @@ function rt.goto_playing()
return
end
- state.depth = 1
- goto_path(path, opt, true)
+ goto_path(1, path, opt, true)
+end
+
+function rt.goto_origin()
+ local menu = state:menu()
+ local origin = menu.origin
+ if not origin then
+ return
+ end
+
+ menu.origin = nil
+ state:restore_origin(origin)
+ if state:menu().group_id == 'favourites' then
+ merge_refreshed_menu_options()
+ end
osd:dirty()
end
diff --git a/state.lua b/state.lua
index 4d97fe3..27a7a01 100644
--- a/state.lua
+++ b/state.lua
@@ -49,6 +49,30 @@ function mt:push_menu(t)
return menu
end
+function mt:capture_origin(d)
+ local m = self.menus[d]
+ return {
+ menus = util.copy_table(self.menus),
+ depth = self.depth,
+ div_depth = d,
+ div_cursor = m.cursor,
+ div_view_top = m.view_top,
+ div_sort_f = m.sort_f,
+ }
+end
+
+function mt:restore_origin(t)
+ self.menus = t.menus
+ self.depth = t.depth
+ local m = self.menus[t.div_depth]
+ m.cursor = t.div_cursor
+ m.view_top = t.div_view_top
+
+ if m.sort_f ~= t.div_sort_f then
+ m:set_sort(t.div_sort_f)
+ end
+end
+
-- returns index if found
function mt:favourited(id)
for i, v in ipairs(self.favourites) do