From ac5683ba93d134c9d24cd59fb7cfe580898a0a48 Mon Sep 17 00:00:00 2001 From: Guldoman Date: Sat, 29 Apr 2023 18:50:39 +0200 Subject: [PATCH] Restore horizontal scroll position after scale change (#494) * Restore horizontal scroll position after scale change * Consider `View` horizontal size when restoring horizontal scroll This is needed because `View:get_h_scrollable_size` includes the horizontal size, while `View.scroll.x` doesn't. --- data/plugins/scale.lua | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/data/plugins/scale.lua b/data/plugins/scale.lua index 7c9e6d4c..89a016b7 100644 --- a/data/plugins/scale.lua +++ b/data/plugins/scale.lua @@ -25,11 +25,16 @@ local function set_scale(scale) scale = common.clamp(scale, 0.2, 6) -- save scroll positions - local scrolls = {} + local v_scrolls = {} + local h_scrolls = {} for _, view in ipairs(core.root_view.root_node:get_children()) do local n = view:get_scrollable_size() - if n ~= math.huge and not view:is(CommandView) and n > view.size.y then - scrolls[view] = view.scroll.y / (n - view.size.y) + if n ~= math.huge and n > view.size.y then + v_scrolls[view] = view.scroll.y / (n - view.size.y) + end + local hn = view:get_h_scrollable_size() + if hn ~= math.huge and hn > view.size.x then + h_scrolls[view] = view.scroll.x / (hn - view.size.x) end end @@ -59,10 +64,14 @@ local function set_scale(scale) end -- restore scroll positions - for view, n in pairs(scrolls) do + for view, n in pairs(v_scrolls) do view.scroll.y = n * (view:get_scrollable_size() - view.size.y) view.scroll.to.y = view.scroll.y end + for view, hn in pairs(h_scrolls) do + view.scroll.x = hn * (view:get_h_scrollable_size() - view.size.x) + view.scroll.to.x = view.scroll.x + end core.redraw = true end