QSHQIVF3JASUFN56WXNZRZW2CQAZXB2V43YQJVBZ3FPRTVULZJ6QC CZ6X73VY6CKBHNLFLWA4DXLYVIWI5W4WPDIHJL3N6OBMTXQDC3RQC S7CSVBHZ4AORIP4VIQETFAVXVMNKERVOI5DENNTU73ZO2L667N7QC R5QXEHUIZLELJGGCZAE7ATNS3CLRJ7JFRENMGH4XXH24C5WABZDQC JOPVPUSAMMU6RFVDQR4NJC4GNNUFB7GPKVH7OS5FKCYS5QZ53VLQC 4Y2QDDAZT2X7SEWYNFEMTYJC6O3UBK4ID3AIOAZZNE2S2H57UQSAC RAXUQQ6ZTTH4WCEDDLVXJSZ4E2W6NBEGTANCBDK57YO6ASCEI2CQC 34BZ5ZKNAB4XQGXOPVBZHBDYD5D3X4V6T72XZSR5LJXF4UIVSWQAC I4S4EFYX6P4RSBCCRAYYXA5MD63T3YINN36LOQXXDKMN7MVS6WNAC 3PSFWAILGRA4OYXWS2DX7VF332AIBPYBXHEA4GIQY2XEJVD65UMAC endfunction test_search_downwards_from_end_of_line()App.screen.init{width=120, height=60}Editor_state = edit.initialize_test_state()Editor_state.lines = load_array{'abc', 'def', 'ghi'}Text.redraw_all(Editor_state)Editor_state.cursor1 = {line=1, pos=4}Editor_state.screen_top1 = {line=1, pos=1}edit.draw(Editor_state)-- search for empty stringedit.run_after_keychord(Editor_state, 'C-f', 'f')edit.run_after_keychord(Editor_state, 'down', 'down')-- no crashendfunction test_search_downwards_from_final_pos_of_line()App.screen.init{width=120, height=60}Editor_state = edit.initialize_test_state()Editor_state.lines = load_array{'abc', 'def', 'ghi'}Text.redraw_all(Editor_state)Editor_state.cursor1 = {line=1, pos=3}Editor_state.screen_top1 = {line=1, pos=1}edit.draw(Editor_state)-- search for empty stringedit.run_after_keychord(Editor_state, 'C-f', 'f')edit.run_after_keychord(Editor_state, 'down', 'down')-- no crashend
local line = State.cursor1.linewhile line < #State.lines doline = line+1if State.lines[line].mode == 'text' thenState.cursor1.line = lineState.cursor1.pos = 1endendfunction edit.put_cursor_on_next_text_line_wrapping_around_if_necessary(State)local line = State.cursor1.linelocal max = #State.linesfor _ = 1, max-1 doline = (line+1) % maxif State.lines[line].mode == 'text' thenState.cursor1.line = lineState.cursor1.pos = 1endendfunction edit.put_cursor_on_next_text_loc_wrapping_around_if_necessary(State)local cursor_line = State.lines[State.cursor1.line].dataif State.cursor1.pos <= utf8.len(cursor_line) thenState.cursor1.pos = State.cursor1.pos + 1elseedit.put_cursor_on_next_text_line_wrapping_around_if_necessary(State)State.cursor = deepcopy(State.search_backup.cursor)State.screen_top = deepcopy(State.search_backup.screen_top)elseif chord == 'down' thenif #State.search_term > 0 thenedit.put_cursor_on_next_text_loc_wrapping_around_if_necessary(State)Text.search_next(State)endelseif chord == 'up' thenText.search_previous(State)endreturnelseif chord == 'C-f' thenState.search_term = ''State.search_backup = {Text.search_next(State)endendbreakendbreakend