diff options
| author | bptato <nincsnevem662@gmail.com> | 2025-01-29 18:49:01 +0100 |
|---|---|---|
| committer | bptato <nincsnevem662@gmail.com> | 2025-01-29 18:49:01 +0100 |
| commit | ccc48b4adc98538d57f886a95785f6c9dc3fda95 (patch) | |
| tree | 08116909e9c726be0882400b1efa824f37078147 /src/local | |
| parent | 669c01b24d553c5c51245278a0f2bb7986157188 (diff) | |
| download | chawan-ccc48b4adc98538d57f886a95785f6c9dc3fda95.tar.gz | |
lineedit: add missing nil check to nextHist, prevent empty entries in submit
And clean up the function, while we're at it.
ref. https://todo.sr.ht/~bptato/chawan/45
(The submit bug is unrelated, just something I discovered while testing
nextHist & prevHist.)
Diffstat (limited to 'src/local')
| -rw-r--r-- | src/local/lineedit.nim | 21 |
1 files changed, 9 insertions, 12 deletions
diff --git a/src/local/lineedit.nim b/src/local/lineedit.nim index 2f8e5329..87283a3a 100644 --- a/src/local/lineedit.nim +++ b/src/local/lineedit.nim @@ -122,7 +122,7 @@ proc cancel(edit: LineEdit) {.jsfunc.} = edit.state = lesCancel proc submit(edit: LineEdit) {.jsfunc.} = - if edit.hist.mtime == 0: + if edit.hist.mtime == 0 and edit.news.len > 0: edit.hist.add(edit.news) edit.state = lesFinish @@ -281,18 +281,15 @@ proc prevHist(edit: LineEdit) {.jsfunc.} = edit.redraw = true 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 - elif edit.currHist == edit.hist.last: + if edit.currHist != nil: edit.currHist = edit.currHist.next - edit.news = move(edit.histtmp) - edit.histtmp = "" + if edit.currHist != nil: + edit.news = edit.currHist.s + if edit.currHist == edit.hist.last and edit.skipLast: + edit.currHist = nil + else: + edit.news = move(edit.histtmp) + edit.histtmp = "" edit.begin() edit.end() edit.redraw = true |