From 4968b1da421b7346a5f894bde46c15d4f9779fba Mon Sep 17 00:00:00 2001 From: Paul Ouellette Date: Sat, 1 Oct 2022 09:39:11 -0400 Subject: [PATCH] Reset history position when leaving command line (#953) Previously the history position was only reset when executing the history prev/next command in normal mode, so it was not reset if you entered command-line mode then started moving through the history. --- eval.go | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/eval.go b/eval.go index 085002ed..59596d61 100644 --- a/eval.go +++ b/eval.go @@ -600,6 +600,8 @@ func normal(app *app) { app.ui.cmdAccRight = nil app.ui.cmdTmp = nil app.ui.cmdPrefix = "" + + app.cmdHistoryInd = 0 } func insert(app *app, arg string) { @@ -1884,31 +1886,27 @@ func (e *callExpr) eval(app *app, args []string) { app.cmdHistoryInd-- } if app.cmdHistoryInd == 0 { - app.ui.menuBuf = nil - app.ui.menuSelected = -2 - app.ui.cmdAccLeft = nil - app.ui.cmdAccRight = nil - app.ui.cmdTmp = nil + normal(app) app.ui.cmdPrefix = ":" return } - cmd := app.cmdHistory[len(app.cmdHistory)-app.cmdHistoryInd] + historyInd := app.cmdHistoryInd + cmd := app.cmdHistory[len(app.cmdHistory)-historyInd] normal(app) + app.cmdHistoryInd = historyInd app.ui.cmdPrefix = cmd.prefix app.ui.cmdAccLeft = []rune(cmd.value) case "cmd-history-prev": if app.ui.cmdPrefix == ">" { return } - if app.ui.cmdPrefix == "" { - app.cmdHistoryInd = 0 - } if app.cmdHistoryInd == len(app.cmdHistory) { return } - app.cmdHistoryInd++ - cmd := app.cmdHistory[len(app.cmdHistory)-app.cmdHistoryInd] + historyInd := app.cmdHistoryInd + 1 + cmd := app.cmdHistory[len(app.cmdHistory)-historyInd] normal(app) + app.cmdHistoryInd = historyInd app.ui.cmdPrefix = cmd.prefix app.ui.cmdAccLeft = []rune(cmd.value) case "cmd-delete":