experiment: extremely precise scrolling on paste

But this is too slow.
This commit is contained in:
Kartik K. Agaram 2022-06-10 13:59:15 -07:00
parent 1c56b9d644
commit 019a3b48f1
1 changed files with 5 additions and 15 deletions

View File

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