diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2022-07-21 16:53:54 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2022-07-21 16:55:05 -0700 |
commit | 0251b3f0c2b71a880734d0011c272cadaf3d5d51 (patch) | |
tree | a211ad276597da52c025c9b716a8ea7bd2e7b086 | |
parent | 1937379da31f4c2f4d2635ea3ad9c4cda074e1fe (diff) | |
download | view.love-0251b3f0c2b71a880734d0011c272cadaf3d5d51.tar.gz |
bugfix: search
Broken since commit 188bbc73 9 days ago :/ At least we have a test for it now.
-rw-r--r-- | text.lua | 2 | ||||
-rw-r--r-- | text_tests.lua | 33 |
2 files changed, 34 insertions, 1 deletions
diff --git a/text.lua b/text.lua index b00a08b..3490f7c 100644 --- a/text.lua +++ b/text.lua @@ -51,7 +51,7 @@ function Text.draw(State, line_index, y, startpos) if pos <= State.cursor1.pos and pos + frag_len > State.cursor1.pos then if State.search_term then if State.lines[State.cursor1.line].data:sub(State.cursor1.pos, State.cursor1.pos+utf8.len(State.search_term)-1) == State.search_term then - local lo_px = Text.draw_highlight(line, x,y, pos, State.cursor1.pos, State.cursor1.pos+utf8.len(State.search_term)) + local lo_px = Text.draw_highlight(State, line, x,y, pos, State.cursor1.pos, State.cursor1.pos+utf8.len(State.search_term)) App.color(Text_color) love.graphics.print(State.search_term, x+lo_px,y) end diff --git a/text_tests.lua b/text_tests.lua index 4e3cd2c..a8e75f3 100644 --- a/text_tests.lua +++ b/text_tests.lua @@ -1965,3 +1965,36 @@ function test_undo_restores_selection() check_eq(Editor_state.selection1.line, 1, 'F - test_undo_restores_selection/line') check_eq(Editor_state.selection1.pos, 2, 'F - test_undo_restores_selection/pos') end + +function test_search() + io.write('\ntest_search') + App.screen.init{width=120, height=60} + Editor_state = edit.initialize_test_state() + Editor_state.lines = load_array{'abc', 'def', 'ghi', 'deg'} + Text.redraw_all(Editor_state) + Editor_state.cursor1 = {line=1, pos=1} + Editor_state.screen_top1 = {line=1, pos=1} + Editor_state.screen_bottom1 = {} + edit.draw(Editor_state) + local y = Editor_state.top + App.screen.check(y, 'abc', 'F - test_search/baseline/screen:1') + y = y + Editor_state.line_height + App.screen.check(y, 'def', 'F - test_search/baseline/screen:2') + y = y + Editor_state.line_height + App.screen.check(y, 'ghi', 'F - test_search/baseline/screen:3') + -- search for a string + edit.run_after_keychord(Editor_state, 'C-f') + edit.run_after_textinput(Editor_state, 'd') + edit.run_after_keychord(Editor_state, 'return') + check_eq(Editor_state.cursor1.line, 2, 'F - test_search/1/cursor:line') + check_eq(Editor_state.cursor1.pos, 1, 'F - test_search/1/cursor:pos') + -- reset cursor + Editor_state.cursor1 = {line=1, pos=1} + -- search for second occurrence + edit.run_after_keychord(Editor_state, 'C-f') + edit.run_after_textinput(Editor_state, 'de') + edit.run_after_keychord(Editor_state, 'down') + edit.run_after_keychord(Editor_state, 'return') + check_eq(Editor_state.cursor1.line, 4, 'F - test_search/2/cursor:line') + check_eq(Editor_state.cursor1.pos, 1, 'F - test_search/2/cursor:pos') +end |