about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--main.lua3
-rw-r--r--text.lua7
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()