faster paste

We don't need to perform the scroll calculations after inserting every
single character from the clipboard.
This commit is contained in:
Kartik K. Agaram 2022-06-10 14:02:35 -07:00
parent 41521518a3
commit feedc51227
2 changed files with 11 additions and 13 deletions

View File

@ -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:

View File

@ -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