summaryrefslogtreecommitdiff
path: root/state.lua
diff options
context:
space:
mode:
Diffstat (limited to 'state.lua')
-rw-r--r--state.lua11
1 files changed, 11 insertions, 0 deletions
diff --git a/state.lua b/state.lua
index 2f609c9..8bf4ddd 100644
--- a/state.lua
+++ b/state.lua
@@ -85,6 +85,12 @@ end
function menu_mt:set_cursor(pos, lines, opts)
local pos = math.max(1, math.min(pos, #self.options))
local top = self.view_top
+
+ if not lines then
+ top = pos
+ goto update
+ end
+
if opts and opts.centre then
top = pos - math.floor((lines - 1) / 2)
elseif opts and opts.keep_offset then
@@ -100,8 +106,13 @@ function menu_mt:set_cursor(pos, lines, opts)
top = math.max(1, math.min(top, #self.options - lines + 1))
+ ::update::
+ if pos == self.cursor and top == self.view_top then
+ return false
+ end
self.cursor = pos
self.view_top = top
+ return true
end
function menu_mt:set_sort(bool, f)