about summary refs log tree commit diff stats
path: root/search.lua
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2022-09-03 14:13:22 -0700
committerKartik K. Agaram <vc@akkartik.com>2022-09-03 14:13:22 -0700
commite1c5a42f311fdafd88506726bbe480f3fcc2d1a3 (patch)
tree6628729cc55947d0bd5d306704e88b57680c3514 /search.lua
parent9c72ff1bb4fc1ba08acfb0324079da6fe49f3a4a (diff)
downloadlines.love-e1c5a42f311fdafd88506726bbe480f3fcc2d1a3.tar.gz
editing source code from within the app
integrated from pong.love via text.love:
  https://merveilles.town/@akkartik/108933336531898243
Diffstat (limited to 'search.lua')
-rw-r--r--search.lua20
1 files changed, 8 insertions, 12 deletions
diff --git a/search.lua b/search.lua
index bd28d58..83545c9 100644
--- a/search.lua
+++ b/search.lua
@@ -30,8 +30,7 @@ function Text.search_next(State)
     for i=State.cursor1.line+1,#State.lines do
       pos = find(State.lines[i].data, State.search_term)
       if pos then
-        State.cursor1.line = i
-        State.cursor1.pos = pos
+        State.cursor1 = {line=i, pos=pos}
         break
       end
     end
@@ -41,8 +40,7 @@ function Text.search_next(State)
     for i=1,State.cursor1.line-1 do
       pos = find(State.lines[i].data, State.search_term)
       if pos then
-        State.cursor1.line = i
-        State.cursor1.pos = pos
+        State.cursor1 = {line=i, pos=pos}
         break
       end
     end
@@ -78,8 +76,7 @@ function Text.search_previous(State)
     for i=State.cursor1.line-1,1,-1 do
       pos = rfind(State.lines[i].data, State.search_term)
       if pos then
-        State.cursor1.line = i
-        State.cursor1.pos = pos
+        State.cursor1 = {line=i, pos=pos}
         break
       end
     end
@@ -89,8 +86,7 @@ function Text.search_previous(State)
     for i=#State.lines,State.cursor1.line+1,-1 do
       pos = rfind(State.lines[i].data, State.search_term)
       if pos then
-        State.cursor1.line = i
-        State.cursor1.pos = pos
+        State.cursor1 = {line=i, pos=pos}
         break
       end
     end
@@ -115,18 +111,18 @@ function Text.search_previous(State)
   end
 end
 
-function find(s, pat, i)
+function find(s, pat, i, plain)
   if s == nil then return end
-  return s:find(pat, i)
+  return s:find(pat, i, plain)
 end
 
-function rfind(s, pat, i)
+function rfind(s, pat, i, plain)
   if s == nil then return end
   local rs = s:reverse()
   local rpat = pat:reverse()
   if i == nil then i = #s end
   local ri = #s - i + 1
-  local rendpos = rs:find(rpat, ri)
+  local rendpos = rs:find(rpat, ri, plain)
   if rendpos == nil then return nil end
   local endpos = #s - rendpos + 1
   assert (endpos >= #pat)