bugfix: search
Broken since commit 188bbc73
9 days ago :/ At least we have a test for
it now.
This commit is contained in:
parent
1937379da3
commit
0251b3f0c2
2
text.lua
2
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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue