From 15f3f7f7a7428e97b483ba3c3d0f146e6f77f1e7 Mon Sep 17 00:00:00 2001 From: David Vazgenovich Shakaryan Date: Sat, 10 Jan 2026 14:57:32 -0800 Subject: respect scroll margin on page up/down --- main.lua | 12 ++++++++---- state.lua | 9 ++++++--- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/main.lua b/main.lua index 4014d16..215fbf4 100644 --- a/main.lua +++ b/main.lua @@ -118,12 +118,14 @@ end local function cursor_page_up() set_cursor( - state:menu().cursor - osd_menu_lines(), {keep_offset = true}) + state:menu().cursor - osd_menu_lines(), + {keep_offset = true, margin = config.scroll_margin}) end local function cursor_page_down() set_cursor( - state:menu().cursor + osd_menu_lines(), {keep_offset = true}) + state:menu().cursor + osd_menu_lines(), + {keep_offset = true, margin = config.scroll_margin}) end local function cursor_to_object(id) @@ -180,12 +182,14 @@ end local function move_option_page_up() move_option( - state:menu().cursor - osd_menu_lines(), {keep_offset = true}) + state:menu().cursor - osd_menu_lines(), + {keep_offset = true, margin = config.scroll_margin}) end local function move_option_page_down() move_option( - state:menu().cursor + osd_menu_lines(), {keep_offset = true}) + state:menu().cursor + osd_menu_lines(), + {keep_offset = true, margin = config.scroll_margin}) end local function sort_options(options) diff --git a/state.lua b/state.lua index 41c317c..da26a9a 100644 --- a/state.lua +++ b/state.lua @@ -92,14 +92,17 @@ function menu_mt:set_cursor(pos, lines, opts) goto update end + if opts and opts.margin then + margin = math.min(opts.margin, math.floor((lines - 1) / 2)) + end + if opts and opts.centre then top = pos - math.floor((lines - 1) / 2) elseif opts and opts.keep_offset then top = top + pos - self.cursor - elseif opts and opts.margin then + elseif margin > 0 then margin = math.max(0, math.min( - opts.margin, - math.floor((lines - 1) / 2), + margin, self.cursor - self.view_top, self.view_top + lines - 1 - self.cursor)) end -- cgit v1.2.3-70-g09d2