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MRW2VVBZ567HJQPGLC57LTSBKWH7UFP32IW43D23X6WTEQC while true doText.left()if Cursor1.pos == 1 then break endassert(Cursor1.pos > 1)local offset = utf8.offset(Lines[Cursor1.line].data, Cursor1.pos)assert(offset > 1)if Lines[Cursor1.line].data:sub(offset-1,offset-1) == ' ' thenbreakendend
Text.word_left()
assert(Lines[Cursor1.line].mode == 'text')--? print('up', Cursor1.pos, Screen_top1.pos)local screen_line_index,screen_line_starting_pos = Text.pos_at_start_of_cursor_screen_line()if screen_line_starting_pos == 1 then--? print('cursor is at first screen line of its line')-- line is done; skip to previous text linelocal new_cursor_line = Cursor1.linewhile new_cursor_line > 1 donew_cursor_line = new_cursor_line-1if Lines[new_cursor_line].mode == 'text' then--? print('found previous text line')Cursor1.line = new_cursor_lineText.populate_screen_line_starting_pos(Cursor1.line)if Lines[Cursor1.line].screen_line_starting_pos == nil thenCursor1.pos = Text.nearest_cursor_pos(Lines[Cursor1.line].data, Cursor_x)breakend-- previous text line found, pick its final screen line--? print('has multiple screen lines')local screen_line_starting_pos = Lines[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 Screen_top1.line > Cursor1.line thenScreen_top1.line = Cursor1.lineScreen_top1.pos = screen_line_starting_pos--? print('pos of top of screen is also '..tostring(Screen_top1.pos)..' of the same line')endlocal s = string.sub(Lines[Cursor1.line].data, screen_line_starting_pos)Cursor1.pos = screen_line_starting_pos + Text.nearest_cursor_pos(s, Cursor_x) - 1breakendendif Cursor1.line < Screen_top1.line thenScreen_top1.line = Cursor1.lineendelse-- 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 = Lines[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 Screen_top1.line == Cursor1.line and Screen_top1.pos == screen_line_starting_pos thenScreen_top1.pos = new_screen_line_starting_pos--? print('also setting pos of top of screen to '..tostring(Screen_top1.pos))endlocal s = string.sub(Lines[Cursor1.line].data, new_screen_line_starting_pos)Cursor1.pos = new_screen_line_starting_pos + Text.nearest_cursor_pos(s, Cursor_x) - 1--? print('cursor pos is now '..tostring(Cursor1.pos))end
Text.up()
assert(Lines[Cursor1.line].mode == 'text')--? print('down', Cursor1.line, Cursor1.pos, Screen_top1.line, Screen_top1.pos, Screen_bottom1.line, Screen_bottom1.pos)if Text.cursor_at_final_screen_line() then-- line is done, skip to next text line--? print('cursor at final screen line of its line')--? os.exit(1)local new_cursor_line = Cursor1.linewhile new_cursor_line < #Lines donew_cursor_line = new_cursor_line+1if Lines[new_cursor_line].mode == 'text' thenCursor1.line = new_cursor_line
Text.down()endendfunction Text.up()assert(Lines[Cursor1.line].mode == 'text')--? print('up', Cursor1.pos, Screen_top1.pos)local screen_line_index,screen_line_starting_pos = Text.pos_at_start_of_cursor_screen_line()if screen_line_starting_pos == 1 then--? print('cursor is at first screen line of its line')-- line is done; skip to previous text linelocal new_cursor_line = Cursor1.linewhile new_cursor_line > 1 donew_cursor_line = new_cursor_line-1if Lines[new_cursor_line].mode == 'text' then--? print('found previous text line')Cursor1.line = new_cursor_lineText.populate_screen_line_starting_pos(Cursor1.line)if Lines[Cursor1.line].screen_line_starting_pos == nil then
endif Cursor1.line > Screen_bottom1.line then--? print('screen top before:', Screen_top1.line, Screen_top1.pos)Screen_top1.line = Cursor1.line--? print('scroll up preserving cursor')Text.scroll_up_while_cursor_on_screen()--? print('screen top after:', Screen_top1.line, Screen_top1.pos)endelse-- move down one screen line in current linelocal scroll_up = falseif Cursor1.line > Screen_bottom1.line or (Cursor1.line == Screen_bottom1.line and Cursor1.pos >= Screen_bottom1.pos) thenscroll_up = true
-- previous text line found, pick its final screen line--? print('has multiple screen lines')local screen_line_starting_pos = Lines[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 Screen_top1.line > Cursor1.line thenScreen_top1.line = Cursor1.lineScreen_top1.pos = screen_line_starting_pos--? print('pos of top of screen is also '..tostring(Screen_top1.pos)..' of the same line')endlocal s = string.sub(Lines[Cursor1.line].data, screen_line_starting_pos)Cursor1.pos = screen_line_starting_pos + Text.nearest_cursor_pos(s, Cursor_x) - 1break
--? print('cursor is NOT at final screen line of its line')local screen_line_index, screen_line_starting_pos = Text.pos_at_start_of_cursor_screen_line()new_screen_line_starting_pos = Lines[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))local s = string.sub(Lines[Cursor1.line].data, new_screen_line_starting_pos)Cursor1.pos = new_screen_line_starting_pos + Text.nearest_cursor_pos(s, Cursor_x) - 1--? print('cursor pos is now', Cursor1.line, Cursor1.pos)if scroll_up thenScreen_top1.line = Cursor1.line--? print('scroll up preserving cursor')Text.scroll_up_while_cursor_on_screen()--? print('screen top after:', Screen_top1.line, Screen_top1.pos)
endif Cursor1.line < Screen_top1.line thenScreen_top1.line = Cursor1.lineendelse-- 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 = Lines[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 Screen_top1.line == Cursor1.line and Screen_top1.pos == screen_line_starting_pos thenScreen_top1.pos = new_screen_line_starting_pos--? print('also setting pos of top of screen to '..tostring(Screen_top1.pos))endlocal s = string.sub(Lines[Cursor1.line].data, new_screen_line_starting_pos)Cursor1.pos = new_screen_line_starting_pos + Text.nearest_cursor_pos(s, Cursor_x) - 1--? print('cursor pos is now '..tostring(Cursor1.pos))endendfunction Text.down()assert(Lines[Cursor1.line].mode == 'text')--? print('down', Cursor1.line, Cursor1.pos, Screen_top1.line, Screen_top1.pos, Screen_bottom1.line, Screen_bottom1.pos)if Text.cursor_at_final_screen_line() then-- line is done, skip to next text line--? print('cursor at final screen line of its line')local new_cursor_line = Cursor1.linewhile new_cursor_line < #Lines donew_cursor_line = new_cursor_line+1if Lines[new_cursor_line].mode == 'text' thenCursor1.line = new_cursor_lineCursor1.pos = Text.nearest_cursor_pos(Lines[Cursor1.line].data, Cursor_x)--? print(Cursor1.pos)break
--? print('=>', Cursor1.line, Cursor1.pos, Screen_top1.line, Screen_top1.pos, Screen_bottom1.line, Screen_bottom1.pos)
if Cursor1.line > Screen_bottom1.line then--? print('screen top before:', Screen_top1.line, Screen_top1.pos)Screen_top1.line = Cursor1.line--? print('scroll up preserving cursor')Text.scroll_up_while_cursor_on_screen()--? print('screen top after:', Screen_top1.line, Screen_top1.pos)endelse-- move down one screen line in current linelocal scroll_up = falseif Cursor1.line > Screen_bottom1.line or (Cursor1.line == Screen_bottom1.line and Cursor1.pos >= Screen_bottom1.pos) thenscroll_up = trueend--? print('cursor is NOT at final screen line of its line')local screen_line_index, screen_line_starting_pos = Text.pos_at_start_of_cursor_screen_line()new_screen_line_starting_pos = Lines[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))local s = string.sub(Lines[Cursor1.line].data, new_screen_line_starting_pos)Cursor1.pos = new_screen_line_starting_pos + Text.nearest_cursor_pos(s, Cursor_x) - 1--? print('cursor pos is now', Cursor1.line, Cursor1.pos)if scroll_up thenScreen_top1.line = Cursor1.line--? print('scroll up preserving cursor')Text.scroll_up_while_cursor_on_screen()--? print('screen top after:', Screen_top1.line, Screen_top1.pos)endend--? print('=>', Cursor1.line, Cursor1.pos, Screen_top1.line, Screen_top1.pos, Screen_bottom1.line, Screen_bottom1.pos)endfunction Text.word_left()while true doText.left()if Cursor1.pos == 1 then break endassert(Cursor1.pos > 1)local offset = utf8.offset(Lines[Cursor1.line].data, Cursor1.pos)assert(offset > 1)if Lines[Cursor1.line].data:sub(offset-1,offset-1) == ' ' thenbreakendendendfunction Text.word_right()while true doText.right()if Cursor1.pos > utf8.len(Lines[Cursor1.line].data) then break endlocal offset = utf8.offset(Lines[Cursor1.line].data, Cursor1.pos)if Lines[Cursor1.line].data:sub(offset,offset) == ' ' thenbreakend