about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2024-10-29 16:27:23 -0700
committerKartik K. Agaram <vc@akkartik.com>2024-10-29 16:27:23 -0700
commit0940e7276100c4a368d12e03522aea45bb42b8ed (patch)
tree94ad01a7d2a8f117aa01e85ddc9a7620202bd8f5
parent1693f1f160e0567cf0bf1f26d3d61f577082cdfb (diff)
downloadview.love-0940e7276100c4a368d12e03522aea45bb42b8ed.tar.gz
bugfix #3 in search UI
This is a regression. Scenario: search for a string, then backspace
until it goes empty.
-rw-r--r--edit.lua10
-rw-r--r--search.lua4
2 files changed, 5 insertions, 9 deletions
diff --git a/edit.lua b/edit.lua
index 91ea8e0..9e80cc3 100644
--- a/edit.lua
+++ b/edit.lua
@@ -426,14 +426,10 @@ function edit.keychord_press(State, chord, key)
       State.screen_top = deepcopy(State.search_backup.screen_top)
       Text.search_next(State)
     elseif chord == 'down' then
-      if #State.search_term > 0 then
-        edit.put_cursor_on_next_text_loc_wrapping_around_if_necessary(State)
-        Text.search_next(State)
-      end
+      edit.put_cursor_on_next_text_loc_wrapping_around_if_necessary(State)
+      Text.search_next(State)
     elseif chord == 'up' then
-      if #State.search_term > 0 then
-        Text.search_previous(State)
-      end
+      Text.search_previous(State)
     end
     return
   elseif chord == 'C-f' then
diff --git a/search.lua b/search.lua
index 2b4ea99..4aa1f02 100644
--- a/search.lua
+++ b/search.lua
@@ -17,7 +17,7 @@ function Text.draw_search_bar(State)
 end
 
 function Text.search_next(State)
-  assert(#State.search_term > 0)
+  if #State.search_term == 0 then return end
   -- search current line from cursor
   local curr_pos = State.cursor1.pos
   local curr_line = State.lines[State.cursor1.line].data
@@ -72,7 +72,7 @@ function Text.search_next(State)
 end
 
 function Text.search_previous(State)
-  assert(#State.search_term > 0)
+  if #State.search_term == 0 then return end
   -- search current line before cursor
   local curr_pos = State.cursor1.pos
   local curr_line = State.lines[State.cursor1.line].data