diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2023-03-17 11:03:49 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2023-03-17 11:03:49 -0700 |
commit | 265db2d2fdfffb1b555079afe2050fee344c08ad (patch) | |
tree | 9d39527618146da2d5ade03b52355f296c0b717b /source_edit.lua | |
parent | c4558035c7fb67cb4fba8199235edc0a49dbe5e6 (diff) | |
parent | 4dbc097f835218bc44dd1d96134294a0bc5ce725 (diff) | |
download | view.love-265db2d2fdfffb1b555079afe2050fee344c08ad.tar.gz |
Merge text.love
Diffstat (limited to 'source_edit.lua')
-rw-r--r-- | source_edit.lua | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/source_edit.lua b/source_edit.lua index e17f2f2..f340ab3 100644 --- a/source_edit.lua +++ b/source_edit.lua @@ -115,10 +115,32 @@ function edit.initialize_state(top, left, right, font_height, line_height) -- c return result end -- App.initialize_state -function edit.fixup_cursor(State) +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 not edit.cursor_on_text(State) + or not Text.le1(State.screen_top1, State.cursor1) then + State.screen_top1 = {line=1, pos=1} + edit.put_cursor_on_first_text_line(State) + end +end + +function edit.invalid1(State, loc1) + return loc1.line > #State.lines + or loc1.pos > #State.lines[loc1.line].data +end + +function edit.cursor_on_text(State) + return State.cursor1.line <= #State.lines + and State.lines[State.cursor1.line].mode == 'text' +end + +function edit.put_cursor_on_first_text_line(State) for i,line in ipairs(State.lines) do if line.mode == 'text' then - State.cursor1.line = i + State.cursor1 = {line=i, pos=1} break end end |