get rid of some ridiculous code

I guess I wrote it before I settled into the idiom of:
* first change cursor
* then scroll if necessary
This commit is contained in:
Kartik K. Agaram 2022-08-18 13:04:04 -07:00
parent 0bf34a9ce0
commit 72866ec0ad
1 changed files with 5 additions and 15 deletions

View File

@ -442,36 +442,26 @@ function Text.up(State)
local screen_line_starting_pos = State.line_cache[State.cursor1.line].screen_line_starting_pos
--? print(#screen_line_starting_pos)
screen_line_starting_pos = screen_line_starting_pos[#screen_line_starting_pos]
--? print('previous screen line starts at pos '..tostring(screen_line_starting_pos)..' of its line')
if State.screen_top1.line > State.cursor1.line then
State.screen_top1.line = State.cursor1.line
State.screen_top1.pos = screen_line_starting_pos
--? print('pos of top of screen is also '..tostring(State.screen_top1.pos)..' of the same line')
end
local screen_line_starting_byte_offset = Text.offset(State.lines[State.cursor1.line].data, screen_line_starting_pos)
local s = string.sub(State.lines[State.cursor1.line].data, screen_line_starting_byte_offset)
State.cursor1.pos = screen_line_starting_pos + Text.nearest_cursor_pos(s, State.cursor_x, State.left) - 1
break
end
end
if State.cursor1.line < State.screen_top1.line then
State.screen_top1.line = State.cursor1.line
end
else
-- move up one screen line in current line
--? print('cursor is NOT at first screen line of its line')
assert(screen_line_index > 1)
new_screen_line_starting_pos = State.line_cache[State.cursor1.line].screen_line_starting_pos[screen_line_index-1]
--? print('switching pos of screen line at cursor from '..tostring(screen_line_starting_pos)..' to '..tostring(new_screen_line_starting_pos))
if State.screen_top1.line == State.cursor1.line and State.screen_top1.pos == screen_line_starting_pos then
State.screen_top1.pos = new_screen_line_starting_pos
--? print('also setting pos of top of screen to '..tostring(State.screen_top1.pos))
end
local new_screen_line_starting_byte_offset = Text.offset(State.lines[State.cursor1.line].data, new_screen_line_starting_pos)
local s = string.sub(State.lines[State.cursor1.line].data, new_screen_line_starting_byte_offset)
State.cursor1.pos = new_screen_line_starting_pos + Text.nearest_cursor_pos(s, State.cursor_x, State.left) - 1
--? print('cursor pos is now '..tostring(State.cursor1.pos))
end
if Text.lt1(State.cursor1, State.screen_top1) then
local top2 = Text.to2(State, State.screen_top1)
top2 = Text.previous_screen_line(State, top2)
State.screen_top1 = Text.to1(State, top2)
end
end
function Text.down(State)