diff options
author | rxi <rxi@users.noreply.github.com> | 2020-08-29 22:32:42 +0100 |
---|---|---|
committer | rxi <rxi@users.noreply.github.com> | 2020-08-29 22:32:42 +0100 |
commit | ef3aeeb4e29bb7c1fdab094b03e03b34c93d6468 (patch) | |
tree | 7a470e8d0a244567d6ca1b7f7d371ec2295d01a1 | |
parent | ea3ad14c17684e438c560fd36bf5e5d7c58a4389 (diff) | |
download | lite-xl-plugins-ef3aeeb4e29bb7c1fdab094b03e03b34c93d6468.tar.gz lite-xl-plugins-ef3aeeb4e29bb7c1fdab094b03e03b34c93d6468.zip |
Changed scale plugin to retain scroll positions when scaling
-rw-r--r-- | plugins/scale.lua | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/plugins/scale.lua b/plugins/scale.lua index d3e10e8..6fbf076 100644 --- a/plugins/scale.lua +++ b/plugins/scale.lua @@ -1,9 +1,3 @@ ---[[ - scale.lua - provides support for dynamically adjusting the scale of the code font / UI - version: 20200628_154010 - originally by 6r1d ---]] local core = require "core" local common = require "core.common" local command = require "core.command" @@ -48,6 +42,15 @@ local function get_scale() return current_scale end local function set_scale(scale) scale = common.clamp(scale, 0.2, 6) + -- save scroll positions + local scrolls = {} + for _, view in ipairs(core.root_view.root_node:get_children()) do + local n = view:get_scrollable_size() + if n ~= math.huge then + scrolls[view] = view.scroll.y / (n - view.size.y) + end + end + local s = scale / current_scale current_scale = scale @@ -68,6 +71,12 @@ local function set_scale(scale) style.code_font = scale_font(style.code_font, s) + -- restore scroll positions + for view, n in pairs(scrolls) do + view.scroll.y = n * (view:get_scrollable_size() - view.size.y) + view.scroll.to.y = view.scroll.y + end + core.redraw = true end |