about summary refs log tree commit diff stats
path: root/search.lua
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2022-08-11 20:09:59 -0700
committerKartik K. Agaram <vc@akkartik.com>2022-08-11 22:23:16 -0700
commit0afd03e72128f691d702ec67f317e6fbf407724e (patch)
treeeaed39e6872c64969b4c7d1d792e56fd1eb258c0 /search.lua
parentd14e03d7065e989125f0985e497419dddd50da66 (diff)
downloadlines.love-0afd03e72128f691d702ec67f317e6fbf407724e.tar.gz
bugfix: check before cursor on same line
Diffstat (limited to 'search.lua')
-rw-r--r--search.lua13
1 files changed, 12 insertions, 1 deletions
diff --git a/search.lua b/search.lua
index b578668..95a7f32 100644
--- a/search.lua
+++ b/search.lua
@@ -21,7 +21,7 @@ end
 
 function Text.search_next(State)
   local pos
-  -- search current line
+  -- search current line from cursor
   local line = State.lines[State.cursor1.line]
   if line.mode == 'text' then
     pos = line.data:find(State.search_term, State.cursor1.pos)
@@ -30,6 +30,7 @@ function Text.search_next(State)
     end
   end
   if pos == nil then
+    -- search lines below cursor
     for i=State.cursor1.line+1,#State.lines do
       local line = State.lines[i]
       if line.mode == 'text' then
@@ -54,6 +55,16 @@ function Text.search_next(State)
     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
     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