about summary refs log tree commit diff stats
path: root/text.lua
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2022-06-10 11:21:41 -0700
committerKartik K. Agaram <vc@akkartik.com>2022-06-10 11:21:41 -0700
commit31418976d4da1c72ddb17f24dde22db154962554 (patch)
treebae162353d2b9c96f446db6a38cd6d35a337ee83 /text.lua
parent69c5d844ccc36fcc23d4f2c05783ee493b3b9e00 (diff)
downloadtext.love-31418976d4da1c72ddb17f24dde22db154962554.tar.gz
extract scrolling logic out of insert_return
Diffstat (limited to 'text.lua')
-rw-r--r--text.lua7
1 files changed, 3 insertions, 4 deletions
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()