From 595196f4fa4df7c4b908abd73ec4eeccb94703b5 Mon Sep 17 00:00:00 2001 From: Guldoman Date: Fri, 9 Jun 2023 15:34:34 +0200 Subject: [PATCH] Make `Doc:sanitize_position` return a more appropriate `col` (#1469) If `line` is out of range, return the `col` "closest" to the original values. --- data/core/doc/init.lua | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/data/core/doc/init.lua b/data/core/doc/init.lua index 572b2d78..bf5895fb 100644 --- a/data/core/doc/init.lua +++ b/data/core/doc/init.lua @@ -281,9 +281,13 @@ end -- End of cursor seciton. function Doc:sanitize_position(line, col) - line = common.clamp(line, 1, #self.lines) - col = common.clamp(col, 1, #self.lines[line]) - return line, col + local nlines = #self.lines + if line > nlines then + return nlines, #self.lines[nlines] + elseif line < 1 then + return 1, 1 + end + return line, common.clamp(col, 1, #self.lines[line]) end