summaryrefslogtreecommitdiff
path: root/state.lua
diff options
context:
space:
mode:
authorDavid Vazgenovich Shakaryan <dvshakaryan@gmail.com>2026-01-30 14:17:03 -0800
committerDavid Vazgenovich Shakaryan <dvshakaryan@gmail.com>2026-01-30 14:17:03 -0800
commit37585452259b2c5ae32c3e50e97aa0aca545f52e (patch)
tree98c1be30d6238ce9c1f50531e1040c2bd12ccce4 /state.lua
parent2451df1a217c49b471895941fb1734a25d55ba5c (diff)
downloadmpv-iptv-menu-37585452259b2c5ae32c3e50e97aa0aca545f52e.tar.gz
mpv-iptv-menu-37585452259b2c5ae32c3e50e97aa0aca545f52e.tar.xz
update sort and refresh options logicHEADmaster
Diffstat (limited to 'state.lua')
-rw-r--r--state.lua57
1 files changed, 46 insertions, 11 deletions
diff --git a/state.lua b/state.lua
index a88fe41..326fa28 100644
--- a/state.lua
+++ b/state.lua
@@ -100,6 +100,8 @@ function menu_mt:set_cursor(pos, lines, opts)
top = pos - math.floor((lines - 1) / 2)
elseif opts and opts.keep_offset then
top = top + pos - self.cursor
+ elseif opts and opts.view_top then
+ top = opts.view_top
elseif margin > 0 then
margin = math.max(0, math.min(
margin,
@@ -120,25 +122,58 @@ function menu_mt:set_cursor(pos, lines, opts)
return true
end
-function menu_mt:set_sort(bool, f)
- if not self.sorted == not bool then
- return
- end
+function menu_mt:options_key()
+ return self.type == 'search' and 'search_options' or 'options'
+end
- local key = self.type == 'search' and 'search_options' or 'options'
- if bool then
- self['orig_' .. key] = self[key]
- self[key] = util.copy_table(self[key])
+function menu_mt:set_sort(f)
+ local key = self:options_key()
+ local orig_key = 'orig_' .. key
+
+ if f then
+ if not self[orig_key] then
+ self[orig_key] = self[key]
+ end
+ self[key] = util.copy_table(self[orig_key])
f(self[key])
+ elseif self.sort_f then
+ self[key] = self[orig_key]
+ self[orig_key] = nil
+ end
+
+ self.sort_f = f
+
+ if self.type == 'search' then
+ self:update_search_matches()
+ end
+end
+
+function menu_mt:is_sorted()
+ return self.sort_f ~= nil
+end
+
+function menu_mt:master_options()
+ local key = self:options_key()
+ return self.sort_f and self['orig_' .. key] or self[key]
+end
+
+function menu_mt:set_options(options)
+ local key = self:options_key()
+ if self.sort_f then
+ self['orig_' .. key] = options
+ self[key] = util.copy_table(options)
+ self.sort_f(self[key])
else
- self[key] = self['orig_' .. key]
- self['orig_' .. key] = nil
+ self[key] = options
end
if self.type == 'search' then
self:update_search_matches()
end
- self.sorted = bool
+
+ -- previous position could have become invalid. reset to top and let
+ -- caller deal with remembering position if it is needed.
+ self:set_cursor(1)
end
function menu_mt:set_search_cursor(pos)