about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2024-03-30 15:20:30 +0100
committerbptato <nincsnevem662@gmail.com>2024-03-30 15:33:37 +0100
commitb6afe9fbc9a8c4b6390a90a07b648e898b016698 (patch)
tree95d018e374bb60b39737d5db877c76278e65e113
parentaaf23561d1704e6d178c4acabdfa87a73cd62e9c (diff)
downloadchawan-b6afe9fbc9a8c4b6390a90a07b648e898b016698.tar.gz
pager: fix incremental search with empty string
This is broken in w3m too, so we take nvi behavior instead. Also, we now
consistently complain when the user tries to search for an empty string
instead of just occasionally spitting out "invalid regex" alerts.

(In w3m, /search^M/^M just jumps to the first search result with
ISEARCH. In nvi, it jumps to the second one with both searchincr on
and off.

w3m only produces the latter behavior with regular search, which is I
assume why I made it work this way, but it's still inconsistent for no
good reason.)
-rw-r--r--src/local/pager.nim14
1 files changed, 11 insertions, 3 deletions
diff --git a/src/local/pager.nim b/src/local/pager.nim
index 0d1088d2..4d29f4f0 100644
--- a/src/local/pager.nim
+++ b/src/local/pager.nim
@@ -135,6 +135,9 @@ type
 
 jsDestructor(Pager)
 
+# Forward declarations
+proc alert*(pager: Pager; msg: string)
+
 template attrs(pager: Pager): WindowAttributes =
   pager.term.attrs
 
@@ -205,6 +208,8 @@ proc searchNext(pager: Pager, n = 1) {.jsfunc.} =
     else:
       pager.container.cursorPrevMatch(pager.regex.get, wrap, true, n)
     pager.container.markPos()
+  else:
+    pager.alert("No previous regular expression")
 
 proc searchPrev(pager: Pager, n = 1) {.jsfunc.} =
   if pager.regex.isSome:
@@ -215,6 +220,8 @@ proc searchPrev(pager: Pager, n = 1) {.jsfunc.} =
     else:
       pager.container.cursorNextMatch(pager.regex.get, wrap, true, n)
     pager.container.markPos()
+  else:
+    pager.alert("No previous regular expression")
 
 proc getLineHist(pager: Pager; mode: LineMode): LineHistory =
   if pager.linehist[mode] == nil:
@@ -261,8 +268,6 @@ proc gotoLine[T: string|int](pager: Pager, s: T = "") {.jsfunc.} =
       return
   pager.container.gotoLine(s)
 
-proc alert*(pager: Pager, msg: string)
-
 proc dumpAlerts*(pager: Pager) =
   for msg in pager.alerts:
     stderr.write("cha: " & msg & '\n')
@@ -1071,7 +1076,10 @@ proc updateReadLineISearch(pager: Pager, linemode: LineMode) =
         else:
           pager.container.cursorPrevMatch(pager.iregex.get, wrap, false, 1)
     of lesFinish:
-      pager.regex = pager.checkRegex(pager.iregex)
+      if lineedit.news != "":
+        pager.regex = pager.checkRegex(pager.iregex)
+      else:
+        pager.searchNext()
       pager.reverseSearch = linemode == lmISearchB
       pager.container.markPos()
       pager.container.clearSearchHighlights()