diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2022-06-10 14:02:35 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2022-06-10 14:19:02 -0700 |
commit | feedc512271d62dd4070fa8945385fb4c3242029 (patch) | |
tree | f60581b08c58efb71be2d935dde8f9b66b4e1fd8 | |
parent | 41521518a320985926948d5e2bd217d7e3694eb6 (diff) | |
download | lines.love-feedc512271d62dd4070fa8945385fb4c3242029.tar.gz |
faster paste
We don't need to perform the scroll calculations after inserting every single character from the clipboard.
-rw-r--r-- | README.md | 8 | ||||
-rw-r--r-- | main.lua | 16 |
2 files changed, 11 insertions, 13 deletions
diff --git a/README.md b/README.md index dfbc597..3bbcf98 100644 --- a/README.md +++ b/README.md @@ -73,10 +73,10 @@ found anything amiss: http://akkartik.name/contact * Undo/redo can be sluggish in large files. If things get sluggish, killing the process can lose data. -* Large files may grow sluggish in other ways. Pasting more than a line or two - gets slow. I've noticed in 100KB files that closing the window can take a - few seconds. And it seems to take longer in proportion to how far down my - edits are. The phenomenon persists even if I take out undo history. +* Large files may grow sluggish in other ways. I've noticed in 100KB files + that closing the window can take a few seconds. And it seems to take longer + in proportion to how far down my edits are. The phenomenon persists even if + I take out undo history. * The text cursor will always stay on the screen. This can have some strange implications: diff --git a/main.lua b/main.lua index fc40f99..8013c8d 100644 --- a/main.lua +++ b/main.lua @@ -428,24 +428,22 @@ function App.keychord_pressed(chord) local before = snapshot(before_line) local clipboard_data = App.getClipboardText() local num_newlines = 0 -- hack 1 +--? print(Screen_top1.line, Screen_top1.pos, Cursor1.line, Cursor1.pos, Screen_bottom1.line, Screen_bottom1.pos) for _,code in utf8.codes(clipboard_data) do 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 ---? print(Screen_top1.line, Screen_top1.pos, Cursor1.line, Cursor1.pos, Screen_bottom1.line, Screen_bottom1.pos) Text.insert_at_cursor(c) - if Cursor_y >= App.screen.height - Line_height then - Text.populate_screen_line_starting_pos(Cursor1.line) - Text.snap_cursor_to_bottom_of_screen() ---? print('=>', Screen_top1.line, Screen_top1.pos, Cursor1.line, Cursor1.pos, Screen_bottom1.line, Screen_bottom1.pos) - end end end + App.draw() + if Cursor_y >= App.screen.height - Line_height then + Text.populate_screen_line_starting_pos(Cursor1.line) + Text.snap_cursor_to_bottom_of_screen() +--? print('=>', Screen_top1.line, Screen_top1.pos, Cursor1.line, Cursor1.pos, Screen_bottom1.line, Screen_bottom1.pos) + 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 |