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:
parent
68e9c4670e
commit
f1f81c8851
|
@ -281,9 +281,13 @@ end
|
||||||
-- End of cursor seciton.
|
-- End of cursor seciton.
|
||||||
|
|
||||||
function Doc:sanitize_position(line, col)
|
function Doc:sanitize_position(line, col)
|
||||||
line = common.clamp(line, 1, #self.lines)
|
local nlines = #self.lines
|
||||||
col = common.clamp(col, 1, #self.lines[line])
|
if line > nlines then
|
||||||
return line, col
|
return nlines, #self.lines[nlines]
|
||||||
|
elseif line < 1 then
|
||||||
|
return 1, 1
|
||||||
|
end
|
||||||
|
return line, common.clamp(col, 1, #self.lines[line])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue