From 59ba75916713c5c984e8351d4e819fecee5bd7d8 Mon Sep 17 00:00:00 2001 From: Guldoman Date: Fri, 11 Feb 2022 06:00:38 +0100 Subject: [PATCH 1/2] Don't scroll DocView when executing `doc:select-all` --- data/core/commands/doc.lua | 3 +++ 1 file changed, 3 insertions(+) diff --git a/data/core/commands/doc.lua b/data/core/commands/doc.lua index 2125e185..c2c0e45d 100644 --- a/data/core/commands/doc.lua +++ b/data/core/commands/doc.lua @@ -278,6 +278,9 @@ local commands = { ["doc:select-all"] = function() doc():set_selection(1, 1, math.huge, math.huge) + -- avoid triggering DocView:scroll_to_make_visible + dv().last_line = 1 + dv().last_col = 1 end, ["doc:select-lines"] = function() From 5526041da32a37a11c9f1400b5eaf6fb82a78254 Mon Sep 17 00:00:00 2001 From: Guldoman Date: Fri, 11 Feb 2022 06:04:58 +0100 Subject: [PATCH 2/2] Check entire selection to trigger `DocView:scroll_to_make_visible` This is needed for example when a selection has both `line1` and `col1` at 1, and the left arrow is pressed: `line2` and `col2` change, while `line1` and `col1` don't, but we still want to scroll. --- data/core/commands/doc.lua | 6 ++++-- data/core/docview.lua | 10 ++++++---- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/data/core/commands/doc.lua b/data/core/commands/doc.lua index c2c0e45d..01d85f27 100644 --- a/data/core/commands/doc.lua +++ b/data/core/commands/doc.lua @@ -279,8 +279,10 @@ local commands = { ["doc:select-all"] = function() doc():set_selection(1, 1, math.huge, math.huge) -- avoid triggering DocView:scroll_to_make_visible - dv().last_line = 1 - dv().last_col = 1 + dv().last_line1 = 1 + dv().last_col1 = 1 + dv().last_line2 = #doc().lines + dv().last_col2 = #doc().lines[#doc().lines] end, ["doc:select-lines"] = function() diff --git a/data/core/docview.lua b/data/core/docview.lua index 5bed6215..61a0cc42 100644 --- a/data/core/docview.lua +++ b/data/core/docview.lua @@ -284,13 +284,15 @@ end function DocView:update() -- scroll to make caret visible and reset blink timer if it moved - local line, col = self.doc:get_selection() - if (line ~= self.last_line or col ~= self.last_col) and self.size.x > 0 then + local line1, col1, line2, col2 = self.doc:get_selection() + if (line1 ~= self.last_line1 or col1 ~= self.last_col1 or + line2 ~= self.last_line2 or col2 ~= self.last_col2) and self.size.x > 0 then if core.active_view == self then - self:scroll_to_make_visible(line, col) + self:scroll_to_make_visible(line1, col1) end core.blink_reset() - self.last_line, self.last_col = line, col + self.last_line1, self.last_col1 = line1, col1 + self.last_line2, self.last_col2 = line2, col2 end -- update blink timer