about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--edit.lua6
-rw-r--r--search.lua76
2 files changed, 41 insertions, 41 deletions
diff --git a/edit.lua b/edit.lua
index f5ea9bd..a0ac010 100644
--- a/edit.lua
+++ b/edit.lua
@@ -279,7 +279,7 @@ function edit.textinput(State, t)
   if State.search_term then
     State.search_term = State.search_term..t
     State.search_text = nil
-    Text.search_next()
+    Text.search_next(State)
   elseif State.current_drawing_mode == 'name' then
     local before = snapshot(State, State.lines.current_drawing_index)
     local drawing = State.lines.current_drawing
@@ -320,9 +320,9 @@ function edit.keychord_pressed(State, chord, key)
       State.search_text = nil
     elseif chord == 'down' then
       State.cursor1.pos = State.cursor1.pos+1
-      Text.search_next()
+      Text.search_next(State)
     elseif chord == 'up' then
-      Text.search_previous()
+      Text.search_previous(State)
     end
     return
   elseif chord == 'C-f' then
diff --git a/search.lua b/search.lua
index 64973c3..499eb2b 100644
--- a/search.lua
+++ b/search.lua
@@ -21,83 +21,83 @@ function Text.draw_search_bar(State)
   App.color(Text_color)
 end
 
-function Text.search_next()
+function Text.search_next(State)
   -- 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
-    Editor_state.cursor1.pos = pos
+    State.cursor1.pos = pos
   end
   if pos == nil then
-    for i=Editor_state.cursor1.line+1,#Editor_state.lines do
-      pos = Editor_state.lines[i].data:find(Editor_state.search_term)
+    for i=State.cursor1.line+1,#State.lines do
+      pos = State.lines[i].data:find(State.search_term)
       if pos then
-        Editor_state.cursor1.line = i
-        Editor_state.cursor1.pos = pos
+        State.cursor1.line = i
+        State.cursor1.pos = pos
         break
       end
     end
   end
   if pos == nil then
     -- wrap around
-    for i=1,Editor_state.cursor1.line-1 do
-      pos = Editor_state.lines[i].data:find(Editor_state.search_term)
+    for i=1,State.cursor1.line-1 do
+      pos = State.lines[i].data:find(State.search_term)
       if pos then
-        Editor_state.cursor1.line = i
-        Editor_state.cursor1.pos = pos
+        State.cursor1.line = i
+        State.cursor1.pos = pos
         break
       end
     end
   end
   if pos == nil then
-    Editor_state.cursor1.line = Editor_state.search_backup.cursor.line
-    Editor_state.cursor1.pos = Editor_state.search_backup.cursor.pos
-    Editor_state.screen_top1.line = Editor_state.search_backup.screen_top.line
-    Editor_state.screen_top1.pos = Editor_state.search_backup.screen_top.pos
+    State.cursor1.line = State.search_backup.cursor.line
+    State.cursor1.pos = State.search_backup.cursor.pos
+    State.screen_top1.line = State.search_backup.screen_top.line
+    State.screen_top1.pos = State.search_backup.screen_top.pos
   end
-  if Text.lt1(Editor_state.cursor1, Editor_state.screen_top1) or Text.lt1(Editor_state.screen_bottom1, Editor_state.cursor1) then
-    Editor_state.screen_top1.line = Editor_state.cursor1.line
-    local _, pos = Text.pos_at_start_of_cursor_screen_line(Editor_state.margin_left, App.screen.width-Editor_state.margin_right)
-    Editor_state.screen_top1.pos = pos
+  if Text.lt1(State.cursor1, State.screen_top1) or Text.lt1(State.screen_bottom1, State.cursor1) then
+    State.screen_top1.line = State.cursor1.line
+    local _, pos = Text.pos_at_start_of_cursor_screen_line(State, State.margin_left, App.screen.width-State.margin_right)
+    State.screen_top1.pos = pos
   end
 end
 
-function Text.search_previous()
+function Text.search_previous(State)
   -- 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
-    Editor_state.cursor1.pos = pos
+    State.cursor1.pos = pos
   end
   if pos == nil then
-    for i=Editor_state.cursor1.line-1,1,-1 do
-      pos = rfind(Editor_state.lines[i].data, Editor_state.search_term)
+    for i=State.cursor1.line-1,1,-1 do
+      pos = rfind(State.lines[i].data, State.search_term)
       if pos then
-        Editor_state.cursor1.line = i
-        Editor_state.cursor1.pos = pos
+        State.cursor1.line = i
+        State.cursor1.pos = pos
         break
       end
     end
   end
   if pos == nil then
     -- wrap around
-    for i=#Editor_state.lines,Editor_state.cursor1.line+1,-1 do
-      pos = rfind(Editor_state.lines[i].data, Editor_state.search_term)
+    for i=#State.lines,State.cursor1.line+1,-1 do
+      pos = rfind(State.lines[i].data, State.search_term)
       if pos then
-        Editor_state.cursor1.line = i
-        Editor_state.cursor1.pos = pos
+        State.cursor1.line = i
+        State.cursor1.pos = pos
         break
       end
     end
   end
   if pos == nil then
-    Editor_state.cursor1.line = Editor_state.search_backup.cursor.line
-    Editor_state.cursor1.pos = Editor_state.search_backup.cursor.pos
-    Editor_state.screen_top1.line = Editor_state.search_backup.screen_top.line
-    Editor_state.screen_top1.pos = Editor_state.search_backup.screen_top.pos
+    State.cursor1.line = State.search_backup.cursor.line
+    State.cursor1.pos = State.search_backup.cursor.pos
+    State.screen_top1.line = State.search_backup.screen_top.line
+    State.screen_top1.pos = State.search_backup.screen_top.pos
   end
-  if Text.lt1(Editor_state.cursor1, Editor_state.screen_top1) or Text.lt1(Editor_state.screen_bottom1, Editor_state.cursor1) then
-    Editor_state.screen_top1.line = Editor_state.cursor1.line
-    local _, pos = Text.pos_at_start_of_cursor_screen_line(Editor_state.margin_left, App.screen.width-Editor_state.margin_right)
-    Editor_state.screen_top1.pos = pos
+  if Text.lt1(State.cursor1, State.screen_top1) or Text.lt1(State.screen_bottom1, State.cursor1) then
+    State.screen_top1.line = State.cursor1.line
+    local _, pos = Text.pos_at_start_of_cursor_screen_line(State, State.margin_left, App.screen.width-State.margin_right)
+    State.screen_top1.pos = pos
   end
 end