standardize scroll check in a few places

I'm taking some lessons from pensieve.love here. It seem like specific
pixel thresholds don't matter too much for plain lines.love.

I'd probably feel safer if I just used Text.cursor_out_of_screen in
these places, but it means we draw the screen twice for most events[1].
Let's see if we can get by with the current approach.

[1] Or we have to start scheduling things for the next draw, which is
more complex to orchestrate.
This commit is contained in:
Kartik K. Agaram 2022-08-17 09:40:44 -07:00
parent f029c710b5
commit dd899d2096
1 changed files with 3 additions and 3 deletions

View File

@ -156,7 +156,7 @@ function Text.textinput(State, t)
local before = snapshot(State, State.cursor1.line)
--? print(State.screen_top1.line, State.screen_top1.pos, State.cursor1.line, State.cursor1.pos, State.screen_bottom1.line, State.screen_bottom1.pos)
Text.insert_at_cursor(State, t)
if State.cursor_y >= App.screen.height - State.line_height then
if State.cursor_y > App.screen.height - State.line_height then
Text.populate_screen_line_starting_pos(State, State.cursor1.line)
Text.snap_cursor_to_bottom_of_screen(State, State.left, State.right)
--? print('=>', State.screen_top1.line, State.screen_top1.pos, State.cursor1.line, State.cursor1.pos, State.screen_bottom1.line, State.screen_bottom1.pos)
@ -180,7 +180,7 @@ function Text.keychord_pressed(State, chord)
local before = snapshot(State, before_line)
Text.insert_return(State)
State.selection1 = {}
if (State.cursor_y + State.line_height) > App.screen.height then
if State.cursor_y > App.screen.height - State.line_height then
Text.snap_cursor_to_bottom_of_screen(State, State.left, State.right)
end
schedule_save(State)
@ -189,7 +189,7 @@ function Text.keychord_pressed(State, chord)
local before = snapshot(State, State.cursor1.line)
--? print(State.screen_top1.line, State.screen_top1.pos, State.cursor1.line, State.cursor1.pos, State.screen_bottom1.line, State.screen_bottom1.pos)
Text.insert_at_cursor(State, '\t')
if State.cursor_y >= App.screen.height - State.line_height then
if State.cursor_y > App.screen.height - State.line_height then
Text.populate_screen_line_starting_pos(State, State.cursor1.line)
Text.snap_cursor_to_bottom_of_screen(State, State.left, State.right)
--? print('=>', State.screen_top1.line, State.screen_top1.pos, State.cursor1.line, State.cursor1.pos, State.screen_bottom1.line, State.screen_bottom1.pos)