about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--main.lua20
1 files changed, 15 insertions, 5 deletions
diff --git a/main.lua b/main.lua
index 3af6f77..fc40f99 100644
--- a/main.lua
+++ b/main.lua
@@ -428,13 +428,10 @@ function App.keychord_pressed(chord)
     local before = snapshot(before_line)
     local clipboard_data = App.getClipboardText()
     local num_newlines = 0  -- hack 1
-    local draw_fn = App.draw
-    App.draw = nil  -- disable temporarily
     for _,code in utf8.codes(clipboard_data) do
       local c = utf8.char(code)
       if c == '\n' then
         Text.insert_return()
-        draw_fn()
         if (Cursor_y + Line_height) > App.screen.height then
           Text.snap_cursor_to_bottom_of_screen()
         end
@@ -442,7 +439,6 @@ function App.keychord_pressed(chord)
       else
 --?         print(Screen_top1.line, Screen_top1.pos, Cursor1.line, Cursor1.pos, Screen_bottom1.line, Screen_bottom1.pos)
         Text.insert_at_cursor(c)
-        draw_fn()
         if Cursor_y >= App.screen.height - Line_height then
           Text.populate_screen_line_starting_pos(Cursor1.line)
           Text.snap_cursor_to_bottom_of_screen()
@@ -450,7 +446,21 @@ function App.keychord_pressed(chord)
         end
       end
     end
-    App.draw = draw_fn
+    -- hack 1: if we have too many newlines we definitely need to scroll
+    for i=before_line,Cursor1.line do
+      Lines[i].screen_line_starting_pos = nil
+      Text.populate_screen_line_starting_pos(i)
+    end
+    if Cursor1.line-Screen_top1.line+1 + num_newlines > App.screen.height/Line_height then
+      Text.snap_cursor_to_bottom_of_screen()
+    end
+    -- hack 2: if we have too much text wrapping we definitely need to scroll
+    local clipboard_text = App.newText(love.graphics.getFont(), clipboard_data)
+    local clipboard_width = App.width(clipboard_text)
+--?     print(Cursor_y, Cursor_y*Line_width, Cursor_y*Line_width+Cursor_x, Cursor_y*Line_width+Cursor_x+clipboard_width, Line_width*App.screen.height/Line_height)
+    if Cursor_y*Line_width+Cursor_x + clipboard_width > Line_width*App.screen.height/Line_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)})
   -- dispatch to drawing or text