diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2022-06-10 13:59:15 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2022-06-10 13:59:15 -0700 |
commit | 019a3b48f16aa865b0c2d8fd49ed816045b24da6 (patch) | |
tree | 6a5a2f34c2d12b14305dfdcaf94ccc4457dc8207 /main.lua | |
parent | 1c56b9d644929467fdf030c03deb07aed7e6c71b (diff) | |
download | text.love-019a3b48f16aa865b0c2d8fd49ed816045b24da6.tar.gz |
experiment: extremely precise scrolling on paste
But this is too slow.
Diffstat (limited to 'main.lua')
-rw-r--r-- | main.lua | 20 |
1 files changed, 5 insertions, 15 deletions
diff --git a/main.lua b/main.lua index fc40f99..3af6f77 100644 --- a/main.lua +++ b/main.lua @@ -428,10 +428,13 @@ 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 @@ -439,6 +442,7 @@ 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() @@ -446,21 +450,7 @@ function App.keychord_pressed(chord) end end end - -- 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 + App.draw = draw_fn save_to_disk(Lines, Filename) record_undo_event({before=before, after=snapshot(before_line, Cursor1.line)}) -- dispatch to drawing or text |