add state arg to a few functions
- Text.search_next - Text.search_previous
This commit is contained in:
parent
5b91af1a66
commit
5aae527759
6
edit.lua
6
edit.lua
|
@ -279,7 +279,7 @@ function edit.textinput(State, t)
|
||||||
if State.search_term then
|
if State.search_term then
|
||||||
State.search_term = State.search_term..t
|
State.search_term = State.search_term..t
|
||||||
State.search_text = nil
|
State.search_text = nil
|
||||||
Text.search_next()
|
Text.search_next(State)
|
||||||
elseif State.current_drawing_mode == 'name' then
|
elseif State.current_drawing_mode == 'name' then
|
||||||
local before = snapshot(State, State.lines.current_drawing_index)
|
local before = snapshot(State, State.lines.current_drawing_index)
|
||||||
local drawing = State.lines.current_drawing
|
local drawing = State.lines.current_drawing
|
||||||
|
@ -320,9 +320,9 @@ function edit.keychord_pressed(State, chord, key)
|
||||||
State.search_text = nil
|
State.search_text = nil
|
||||||
elseif chord == 'down' then
|
elseif chord == 'down' then
|
||||||
State.cursor1.pos = State.cursor1.pos+1
|
State.cursor1.pos = State.cursor1.pos+1
|
||||||
Text.search_next()
|
Text.search_next(State)
|
||||||
elseif chord == 'up' then
|
elseif chord == 'up' then
|
||||||
Text.search_previous()
|
Text.search_previous(State)
|
||||||
end
|
end
|
||||||
return
|
return
|
||||||
elseif chord == 'C-f' then
|
elseif chord == 'C-f' then
|
||||||
|
|
76
search.lua
76
search.lua
|
@ -21,83 +21,83 @@ function Text.draw_search_bar(State)
|
||||||
App.color(Text_color)
|
App.color(Text_color)
|
||||||
end
|
end
|
||||||
|
|
||||||
function Text.search_next()
|
function Text.search_next(State)
|
||||||
-- search current line
|
-- search current line
|
||||||
local pos = Editor_state.lines[Editor_state.cursor1.line].data:find(Editor_state.search_term, Editor_state.cursor1.pos)
|
local pos = State.lines[State.cursor1.line].data:find(State.search_term, State.cursor1.pos)
|
||||||
if pos then
|
if pos then
|
||||||
Editor_state.cursor1.pos = pos
|
State.cursor1.pos = pos
|
||||||
end
|
end
|
||||||
if pos == nil then
|
if pos == nil then
|
||||||
for i=Editor_state.cursor1.line+1,#Editor_state.lines do
|
for i=State.cursor1.line+1,#State.lines do
|
||||||
pos = Editor_state.lines[i].data:find(Editor_state.search_term)
|
pos = State.lines[i].data:find(State.search_term)
|
||||||
if pos then
|
if pos then
|
||||||
Editor_state.cursor1.line = i
|
State.cursor1.line = i
|
||||||
Editor_state.cursor1.pos = pos
|
State.cursor1.pos = pos
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if pos == nil then
|
if pos == nil then
|
||||||
-- wrap around
|
-- wrap around
|
||||||
for i=1,Editor_state.cursor1.line-1 do
|
for i=1,State.cursor1.line-1 do
|
||||||
pos = Editor_state.lines[i].data:find(Editor_state.search_term)
|
pos = State.lines[i].data:find(State.search_term)
|
||||||
if pos then
|
if pos then
|
||||||
Editor_state.cursor1.line = i
|
State.cursor1.line = i
|
||||||
Editor_state.cursor1.pos = pos
|
State.cursor1.pos = pos
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if pos == nil then
|
if pos == nil then
|
||||||
Editor_state.cursor1.line = Editor_state.search_backup.cursor.line
|
State.cursor1.line = State.search_backup.cursor.line
|
||||||
Editor_state.cursor1.pos = Editor_state.search_backup.cursor.pos
|
State.cursor1.pos = State.search_backup.cursor.pos
|
||||||
Editor_state.screen_top1.line = Editor_state.search_backup.screen_top.line
|
State.screen_top1.line = State.search_backup.screen_top.line
|
||||||
Editor_state.screen_top1.pos = Editor_state.search_backup.screen_top.pos
|
State.screen_top1.pos = State.search_backup.screen_top.pos
|
||||||
end
|
end
|
||||||
if Text.lt1(Editor_state.cursor1, Editor_state.screen_top1) or Text.lt1(Editor_state.screen_bottom1, Editor_state.cursor1) then
|
if Text.lt1(State.cursor1, State.screen_top1) or Text.lt1(State.screen_bottom1, State.cursor1) then
|
||||||
Editor_state.screen_top1.line = Editor_state.cursor1.line
|
State.screen_top1.line = State.cursor1.line
|
||||||
local _, pos = Text.pos_at_start_of_cursor_screen_line(Editor_state.margin_left, App.screen.width-Editor_state.margin_right)
|
local _, pos = Text.pos_at_start_of_cursor_screen_line(State, State.margin_left, App.screen.width-State.margin_right)
|
||||||
Editor_state.screen_top1.pos = pos
|
State.screen_top1.pos = pos
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function Text.search_previous()
|
function Text.search_previous(State)
|
||||||
-- search current line
|
-- search current line
|
||||||
local pos = rfind(Editor_state.lines[Editor_state.cursor1.line].data, Editor_state.search_term, Editor_state.cursor1.pos)
|
local pos = rfind(State.lines[State.cursor1.line].data, State.search_term, State.cursor1.pos)
|
||||||
if pos then
|
if pos then
|
||||||
Editor_state.cursor1.pos = pos
|
State.cursor1.pos = pos
|
||||||
end
|
end
|
||||||
if pos == nil then
|
if pos == nil then
|
||||||
for i=Editor_state.cursor1.line-1,1,-1 do
|
for i=State.cursor1.line-1,1,-1 do
|
||||||
pos = rfind(Editor_state.lines[i].data, Editor_state.search_term)
|
pos = rfind(State.lines[i].data, State.search_term)
|
||||||
if pos then
|
if pos then
|
||||||
Editor_state.cursor1.line = i
|
State.cursor1.line = i
|
||||||
Editor_state.cursor1.pos = pos
|
State.cursor1.pos = pos
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if pos == nil then
|
if pos == nil then
|
||||||
-- wrap around
|
-- wrap around
|
||||||
for i=#Editor_state.lines,Editor_state.cursor1.line+1,-1 do
|
for i=#State.lines,State.cursor1.line+1,-1 do
|
||||||
pos = rfind(Editor_state.lines[i].data, Editor_state.search_term)
|
pos = rfind(State.lines[i].data, State.search_term)
|
||||||
if pos then
|
if pos then
|
||||||
Editor_state.cursor1.line = i
|
State.cursor1.line = i
|
||||||
Editor_state.cursor1.pos = pos
|
State.cursor1.pos = pos
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if pos == nil then
|
if pos == nil then
|
||||||
Editor_state.cursor1.line = Editor_state.search_backup.cursor.line
|
State.cursor1.line = State.search_backup.cursor.line
|
||||||
Editor_state.cursor1.pos = Editor_state.search_backup.cursor.pos
|
State.cursor1.pos = State.search_backup.cursor.pos
|
||||||
Editor_state.screen_top1.line = Editor_state.search_backup.screen_top.line
|
State.screen_top1.line = State.search_backup.screen_top.line
|
||||||
Editor_state.screen_top1.pos = Editor_state.search_backup.screen_top.pos
|
State.screen_top1.pos = State.search_backup.screen_top.pos
|
||||||
end
|
end
|
||||||
if Text.lt1(Editor_state.cursor1, Editor_state.screen_top1) or Text.lt1(Editor_state.screen_bottom1, Editor_state.cursor1) then
|
if Text.lt1(State.cursor1, State.screen_top1) or Text.lt1(State.screen_bottom1, State.cursor1) then
|
||||||
Editor_state.screen_top1.line = Editor_state.cursor1.line
|
State.screen_top1.line = State.cursor1.line
|
||||||
local _, pos = Text.pos_at_start_of_cursor_screen_line(Editor_state.margin_left, App.screen.width-Editor_state.margin_right)
|
local _, pos = Text.pos_at_start_of_cursor_screen_line(State, State.margin_left, App.screen.width-State.margin_right)
|
||||||
Editor_state.screen_top1.pos = pos
|
State.screen_top1.pos = pos
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user