diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2022-06-10 11:21:41 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2022-06-10 11:21:41 -0700 |
commit | 31418976d4da1c72ddb17f24dde22db154962554 (patch) | |
tree | bae162353d2b9c96f446db6a38cd6d35a337ee83 | |
parent | 69c5d844ccc36fcc23d4f2c05783ee493b3b9e00 (diff) | |
download | text.love-31418976d4da1c72ddb17f24dde22db154962554.tar.gz |
extract scrolling logic out of insert_return
-rw-r--r-- | main.lua | 3 | ||||
-rw-r--r-- | text.lua | 7 |
2 files changed, 6 insertions, 4 deletions
diff --git a/main.lua b/main.lua index eacc8af..8b20ca4 100644 --- a/main.lua +++ b/main.lua @@ -420,6 +420,9 @@ function App.keychord_pressed(chord) local c = utf8.char(code) if c == '\n' then Text.insert_return() + if (Cursor_y + Line_height) > App.screen.height then + Text.snap_cursor_to_bottom_of_screen() + end num_newlines = num_newlines+1 else Text.insert_at_cursor(c) diff --git a/text.lua b/text.lua index 758bf5c..e7fe598 100644 --- a/text.lua +++ b/text.lua @@ -179,6 +179,9 @@ function Text.keychord_pressed(chord) local before_line = Cursor1.line local before = snapshot(before_line) Text.insert_return() + if (Cursor_y + Line_height) > App.screen.height then + Text.snap_cursor_to_bottom_of_screen() + end save_to_disk(Lines, Filename) record_undo_event({before=before, after=snapshot(before_line, Cursor1.line)}) elseif chord == 'tab' then @@ -372,14 +375,10 @@ end function Text.insert_return() local byte_offset = utf8.offset(Lines[Cursor1.line].data, Cursor1.pos) table.insert(Lines, Cursor1.line+1, {mode='text', data=string.sub(Lines[Cursor1.line].data, byte_offset)}) - local scroll_down = (Cursor_y + Line_height) > App.screen.height Lines[Cursor1.line].data = string.sub(Lines[Cursor1.line].data, 1, byte_offset-1) Lines[Cursor1.line].fragments = nil Cursor1.line = Cursor1.line+1 Cursor1.pos = 1 - if scroll_down then - Text.snap_cursor_to_bottom_of_screen() - end end function Text.pageup() |