bugfix: avoid scrolling on 'end'
There's multiple ways to do this, only one of them is right, and I keep forgetting what it is. Turn it into a method.
This commit is contained in:
parent
3422d92a00
commit
f2e5c4ffee
3
main.lua
3
main.lua
|
@ -517,8 +517,7 @@ function App.keychord_pressed(chord, key)
|
||||||
Text.insert_at_cursor(c)
|
Text.insert_at_cursor(c)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
App.draw()
|
if Text.cursor_past_screen_bottom() then
|
||||||
if Cursor_y >= App.screen.height - Line_height then
|
|
||||||
Text.snap_cursor_to_bottom_of_screen()
|
Text.snap_cursor_to_bottom_of_screen()
|
||||||
end
|
end
|
||||||
schedule_save()
|
schedule_save()
|
||||||
|
|
20
text.lua
20
text.lua
|
@ -509,7 +509,7 @@ function Text.end_of_line()
|
||||||
Cursor1.pos = utf8.len(Lines[Cursor1.line].data) + 1
|
Cursor1.pos = utf8.len(Lines[Cursor1.line].data) + 1
|
||||||
local _,botpos = Text.pos_at_start_of_cursor_screen_line()
|
local _,botpos = Text.pos_at_start_of_cursor_screen_line()
|
||||||
local botline1 = {line=Cursor1.line, pos=botpos}
|
local botline1 = {line=Cursor1.line, pos=botpos}
|
||||||
if Text.lt1(Screen_bottom1, botline1) then
|
if Text.cursor_past_screen_bottom() then
|
||||||
Text.snap_cursor_to_bottom_of_screen()
|
Text.snap_cursor_to_bottom_of_screen()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -575,9 +575,7 @@ function Text.right()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
local _,botpos = Text.pos_at_start_of_cursor_screen_line()
|
if Text.cursor_past_screen_bottom() then
|
||||||
local botline1 = {line=Cursor1.line, pos=botpos}
|
|
||||||
if Text.lt1(Screen_bottom1, botline1) then
|
|
||||||
Text.snap_cursor_to_bottom_of_screen()
|
Text.snap_cursor_to_bottom_of_screen()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -941,8 +939,7 @@ function Text.tweak_screen_top_and_cursor()
|
||||||
Cursor1 = {line=Screen_top1.line, pos=Screen_top1.pos}
|
Cursor1 = {line=Screen_top1.line, pos=Screen_top1.pos}
|
||||||
elseif Cursor1.line >= Screen_bottom1.line then
|
elseif Cursor1.line >= Screen_bottom1.line then
|
||||||
--? print('too low')
|
--? print('too low')
|
||||||
App.draw()
|
if Text.cursor_past_screen_bottom() then
|
||||||
if Text.lt1(Screen_bottom1, Cursor1) then
|
|
||||||
--? print('tweak')
|
--? print('tweak')
|
||||||
local line = Lines[Screen_bottom1.line]
|
local line = Lines[Screen_bottom1.line]
|
||||||
Cursor1 = {line=Screen_bottom1.line, pos=Text.to_pos_on_line(line, App.screen.width-5, App.screen.height-5)}
|
Cursor1 = {line=Screen_bottom1.line, pos=Text.to_pos_on_line(line, App.screen.width-5, App.screen.height-5)}
|
||||||
|
@ -950,6 +947,17 @@ function Text.tweak_screen_top_and_cursor()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- slightly expensive since it redraws the screen
|
||||||
|
function Text.cursor_past_screen_bottom()
|
||||||
|
App.draw()
|
||||||
|
return Cursor_y >= App.screen.height - Line_height
|
||||||
|
-- this approach is cheaper and almost works, except on the final screen
|
||||||
|
-- where file ends above bottom of screen
|
||||||
|
--? local _,botpos = Text.pos_at_start_of_cursor_screen_line()
|
||||||
|
--? local botline1 = {line=Cursor1.line, pos=botpos}
|
||||||
|
--? return Text.lt1(Screen_bottom1, botline1)
|
||||||
|
end
|
||||||
|
|
||||||
function Text.redraw_all()
|
function Text.redraw_all()
|
||||||
--? print('clearing fragments')
|
--? print('clearing fragments')
|
||||||
for _,line in ipairs(Lines) do
|
for _,line in ipairs(Lines) do
|
||||||
|
|
Loading…
Reference in New Issue