bugfix: check before cursor on same line
This commit is contained in:
parent
d14e03d706
commit
0afd03e721
13
search.lua
13
search.lua
|
@ -21,7 +21,7 @@ end
|
||||||
|
|
||||||
function Text.search_next(State)
|
function Text.search_next(State)
|
||||||
local pos
|
local pos
|
||||||
-- search current line
|
-- search current line from cursor
|
||||||
local line = State.lines[State.cursor1.line]
|
local line = State.lines[State.cursor1.line]
|
||||||
if line.mode == 'text' then
|
if line.mode == 'text' then
|
||||||
pos = line.data:find(State.search_term, State.cursor1.pos)
|
pos = line.data:find(State.search_term, State.cursor1.pos)
|
||||||
|
@ -30,6 +30,7 @@ function Text.search_next(State)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if pos == nil then
|
if pos == nil then
|
||||||
|
-- search lines below cursor
|
||||||
for i=State.cursor1.line+1,#State.lines do
|
for i=State.cursor1.line+1,#State.lines do
|
||||||
local line = State.lines[i]
|
local line = State.lines[i]
|
||||||
if line.mode == 'text' then
|
if line.mode == 'text' then
|
||||||
|
@ -53,6 +54,16 @@ function Text.search_next(State)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
if pos == nil then
|
||||||
|
-- search current line until cursor
|
||||||
|
local line = State.lines[State.cursor1.line]
|
||||||
|
if line.mode == 'text' then
|
||||||
|
pos = line.data:find(State.search_term)
|
||||||
|
if pos and pos < State.cursor1.pos then
|
||||||
|
State.cursor1.pos = pos
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
if pos == nil then
|
if pos == nil then
|
||||||
State.cursor1.line = State.search_backup.cursor.line
|
State.cursor1.line = State.search_backup.cursor.line
|
||||||
State.cursor1.pos = State.search_backup.cursor.pos
|
State.cursor1.pos = State.search_backup.cursor.pos
|
||||||
|
|
|
@ -2045,3 +2045,22 @@ function test_search()
|
||||||
check_eq(Editor_state.cursor1.line, 4, 'F - test_search/2/cursor:line')
|
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')
|
check_eq(Editor_state.cursor1.pos, 1, 'F - test_search/2/cursor:pos')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function test_search_wrap()
|
||||||
|
io.write('\ntest_search_wrap')
|
||||||
|
App.screen.init{width=120, height=60}
|
||||||
|
Editor_state = edit.initialize_test_state()
|
||||||
|
Editor_state.lines = load_array{'abc'}
|
||||||
|
Text.redraw_all(Editor_state)
|
||||||
|
Editor_state.cursor1 = {line=1, pos=3}
|
||||||
|
Editor_state.screen_top1 = {line=1, pos=1}
|
||||||
|
Editor_state.screen_bottom1 = {}
|
||||||
|
edit.draw(Editor_state)
|
||||||
|
-- search for a string
|
||||||
|
edit.run_after_keychord(Editor_state, 'C-f')
|
||||||
|
edit.run_after_textinput(Editor_state, 'a')
|
||||||
|
edit.run_after_keychord(Editor_state, 'return')
|
||||||
|
-- cursor wraps
|
||||||
|
check_eq(Editor_state.cursor1.line, 1, 'F - test_search_wrap/1/cursor:line')
|
||||||
|
check_eq(Editor_state.cursor1.pos, 1, 'F - test_search_wrap/1/cursor:pos')
|
||||||
|
end
|
||||||
|
|
Loading…
Reference in New Issue