Make `Doc:sanitize_position` return a more appropriate `col` (#1469)

If `line` is out of range, return the `col` "closest" to the original
values.
This commit is contained in:
Guldoman 2023-06-09 15:34:34 +02:00 committed by George Sokianos
parent d12a14869c
commit 9b61f1c597
1 changed files with 7 additions and 3 deletions

View File

@ -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