diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2023-06-08 01:13:12 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2023-06-08 01:13:12 -0700 |
commit | 3c6523e5a5a8f01953cf72df60e6005e34bd7591 (patch) | |
tree | 6192615f2180f52438be8998b7fee3fc20768b4a /edit.lua | |
parent | 037fb843c86f34b640d32c9776971f8aa5e448e0 (diff) | |
parent | fdb2172843ae7bd3acfb8fcb0f02b3dede301857 (diff) | |
download | view.love-3c6523e5a5a8f01953cf72df60e6005e34bd7591.tar.gz |
Merge text.love
Diffstat (limited to 'edit.lua')
-rw-r--r-- | edit.lua | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/edit.lua b/edit.lua index 8ccb9d4..302e5e2 100644 --- a/edit.lua +++ b/edit.lua @@ -68,7 +68,7 @@ function edit.check_locs(State) -- if State is inconsistent (i.e. file changed by some other program), -- throw away all cursor state entirely if edit.invalid1(State, State.screen_top1) - or edit.invalid1(State, State.cursor1) + or edit.invalid_cursor1(State) or not Text.le1(State.screen_top1, State.cursor1) then State.screen_top1 = {line=1, pos=1} State.cursor1 = {line=1, pos=1} @@ -82,6 +82,16 @@ function edit.invalid1(State, loc1) return loc1.pos > #State.lines[loc1.line].data end +-- cursor loc in particular differs from other locs in one way: +-- pos might occur just after end of line +function edit.invalid_cursor1(State) + local cursor1 = State.cursor1 + if cursor1.line > #State.lines then return true end + local l = State.lines[cursor1.line] + if l.mode ~= 'text' then return false end -- pos is irrelevant to validity for a drawing line + return cursor1.pos > #State.lines[cursor1.line].data + 1 +end + -- return y drawn until function edit.draw(State) App.color(Text_color) |