about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2025-01-08 19:46:31 +0100
committerbptato <nincsnevem662@gmail.com>2025-01-08 21:05:46 +0100
commit2b6a7a4b346c26834e9d8fdc6d9c3fdd09c248d1 (patch)
tree44b0cd2f4ac4e76ffb4ec471da960c326eca033a /src
parent5c3deb4180c8b0109273954a95d5187959813ef6 (diff)
downloadchawan-2b6a7a4b346c26834e9d8fdc6d9c3fdd09c248d1.tar.gz
lineedit: skip last history entry if identical to input
Diffstat (limited to 'src')
-rw-r--r--src/local/lineedit.nim20
1 files changed, 14 insertions, 6 deletions
diff --git a/src/local/lineedit.nim b/src/local/lineedit.nim
index 4346ddd8..2f8e5329 100644
--- a/src/local/lineedit.nim
+++ b/src/local/lineedit.nim
@@ -22,19 +22,20 @@ type
     prompt: string
     promptw: int
     state*: LineEditState
-    escNext*: bool
     cursorx: int # 0 ..< news.width
     cursori: int # 0 ..< news.len
     shiftx: int # 0 ..< news.width
     shifti: int # 0 ..< news.len
     padding: int # 0 or 1
     maxwidth: int
-    hide: bool
     hist: History
     currHist: HistoryEntry
     histtmp: string
     luctx: LUContext
     redraw*: bool
+    skipLast: bool
+    escNext*: bool
+    hide: bool
 
 jsDestructor(LineEdit)
 
@@ -263,9 +264,12 @@ proc `end`(edit: LineEdit) {.jsfunc.} =
 
 proc prevHist(edit: LineEdit) {.jsfunc.} =
   if edit.currHist == nil:
-    if edit.hist.last != nil and edit.news.len > 0:
-      edit.histtmp = $edit.news
-    edit.currHist = edit.hist.last
+    var last = edit.hist.last
+    if last != nil and edit.skipLast:
+      last = last.prev
+    if last != nil and edit.news.len > 0:
+      edit.histtmp = edit.news
+    edit.currHist = last
   elif edit.currHist.prev != nil:
     edit.currHist = edit.currHist.prev
   if edit.currHist != nil:
@@ -280,6 +284,8 @@ proc nextHist(edit: LineEdit) {.jsfunc.} =
   if edit.currHist != nil and edit.currHist != edit.hist.last:
     edit.currHist = edit.currHist.next
     edit.news = edit.currHist.s
+    if edit.currHist == edit.hist.last and edit.skipLast:
+      edit.currHist = nil
     edit.begin()
     edit.end()
     edit.redraw = true
@@ -309,7 +315,9 @@ proc readLine*(prompt, current: string; termwidth: int; hide: bool;
     maxwidth: termwidth - promptw - 1,
     hist: hist,
     currHist: nil,
-    luctx: luctx
+    luctx: luctx,
+    # Skip the last history entry if it's identical to the input.
+    skipLast: hist.last != nil and hist.last.s == current
   )
 
 proc addLineEditModule*(ctx: JSContext) =