simplify cursor-on-screen check
This commit is contained in:
parent
1d710912cc
commit
f029c710b5
8
edit.lua
8
edit.lua
|
@ -134,7 +134,8 @@ function edit.draw(State)
|
||||||
print(State.screen_top1.line, State.screen_top1.pos, State.cursor1.line, State.cursor1.pos)
|
print(State.screen_top1.line, State.screen_top1.pos, State.cursor1.line, State.cursor1.pos)
|
||||||
assert(false)
|
assert(false)
|
||||||
end
|
end
|
||||||
State.cursor_y = -1
|
State.cursor_x = nil
|
||||||
|
State.cursor_y = nil
|
||||||
local y = State.top
|
local y = State.top
|
||||||
--? print('== draw')
|
--? print('== draw')
|
||||||
for line_index = State.screen_top1.line,#State.lines do
|
for line_index = State.screen_top1.line,#State.lines do
|
||||||
|
@ -176,9 +177,6 @@ function edit.draw(State)
|
||||||
assert(false)
|
assert(false)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if State.cursor_y == -1 then
|
|
||||||
State.cursor_y = App.screen.height
|
|
||||||
end
|
|
||||||
--? print('screen bottom: '..tostring(State.screen_bottom1.pos)..' in '..tostring(State.lines[State.screen_bottom1.line].data))
|
--? print('screen bottom: '..tostring(State.screen_bottom1.pos)..' in '..tostring(State.lines[State.screen_bottom1.line].data))
|
||||||
if State.search_term then
|
if State.search_term then
|
||||||
Text.draw_search_bar(State)
|
Text.draw_search_bar(State)
|
||||||
|
@ -408,7 +406,7 @@ function edit.keychord_pressed(State, chord, key)
|
||||||
Text.insert_at_cursor(State, c)
|
Text.insert_at_cursor(State, c)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if Text.cursor_past_screen_bottom(State) then
|
if Text.cursor_out_of_screen(State) then
|
||||||
Text.snap_cursor_to_bottom_of_screen(State, State.left, State.right)
|
Text.snap_cursor_to_bottom_of_screen(State, State.left, State.right)
|
||||||
end
|
end
|
||||||
schedule_save(State)
|
schedule_save(State)
|
||||||
|
|
12
text.lua
12
text.lua
|
@ -528,7 +528,7 @@ function Text.end_of_line(State)
|
||||||
State.cursor1.pos = utf8.len(State.lines[State.cursor1.line].data) + 1
|
State.cursor1.pos = utf8.len(State.lines[State.cursor1.line].data) + 1
|
||||||
local botpos = Text.pos_at_start_of_cursor_screen_line(State)
|
local botpos = Text.pos_at_start_of_cursor_screen_line(State)
|
||||||
local botline1 = {line=State.cursor1.line, pos=botpos}
|
local botline1 = {line=State.cursor1.line, pos=botpos}
|
||||||
if Text.cursor_past_screen_bottom(State) then
|
if Text.cursor_out_of_screen(State) then
|
||||||
Text.snap_cursor_to_bottom_of_screen(State)
|
Text.snap_cursor_to_bottom_of_screen(State)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -577,7 +577,7 @@ function Text.word_right(State)
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if Text.cursor_past_screen_bottom(State) then
|
if Text.cursor_out_of_screen(State) then
|
||||||
Text.snap_cursor_to_bottom_of_screen(State)
|
Text.snap_cursor_to_bottom_of_screen(State)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -615,7 +615,7 @@ end
|
||||||
|
|
||||||
function Text.right(State)
|
function Text.right(State)
|
||||||
Text.right_without_scroll(State)
|
Text.right_without_scroll(State)
|
||||||
if Text.cursor_past_screen_bottom(State) then
|
if Text.cursor_out_of_screen(State) then
|
||||||
Text.snap_cursor_to_bottom_of_screen(State)
|
Text.snap_cursor_to_bottom_of_screen(State)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -968,7 +968,7 @@ function Text.tweak_screen_top_and_cursor(State)
|
||||||
State.cursor1 = {line=State.screen_top1.line, pos=State.screen_top1.pos}
|
State.cursor1 = {line=State.screen_top1.line, pos=State.screen_top1.pos}
|
||||||
elseif State.cursor1.line >= State.screen_bottom1.line then
|
elseif State.cursor1.line >= State.screen_bottom1.line then
|
||||||
--? print('too low')
|
--? print('too low')
|
||||||
if Text.cursor_past_screen_bottom(State) then
|
if Text.cursor_out_of_screen(State) then
|
||||||
--? print('tweak')
|
--? print('tweak')
|
||||||
State.cursor1 = {
|
State.cursor1 = {
|
||||||
line=State.screen_bottom1.line,
|
line=State.screen_bottom1.line,
|
||||||
|
@ -979,9 +979,9 @@ function Text.tweak_screen_top_and_cursor(State)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- slightly expensive since it redraws the screen
|
-- slightly expensive since it redraws the screen
|
||||||
function Text.cursor_past_screen_bottom(State)
|
function Text.cursor_out_of_screen(State)
|
||||||
App.draw()
|
App.draw()
|
||||||
return State.cursor_y >= App.screen.height - State.line_height
|
return State.cursor_y == nil
|
||||||
-- this approach is cheaper and almost works, except on the final screen
|
-- this approach is cheaper and almost works, except on the final screen
|
||||||
-- where file ends above bottom of screen
|
-- where file ends above bottom of screen
|
||||||
--? local botpos = Text.pos_at_start_of_cursor_screen_line(State)
|
--? local botpos = Text.pos_at_start_of_cursor_screen_line(State)
|
||||||
|
|
Loading…
Reference in New Issue