From 38d036d96fd6760192ec5425f0f5e1d8fcd503eb Mon Sep 17 00:00:00 2001 From: sammyette Date: Fri, 14 Jun 2024 08:23:12 -0400 Subject: [PATCH] fix: history navigation going out of bounds --- readline/history.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/readline/history.go b/readline/history.go index e226b4d..0c87a62 100644 --- a/readline/history.go +++ b/readline/history.go @@ -128,15 +128,19 @@ func (rl *Instance) walkHistory(i int) { } rl.histOffset += i + historyLen := history.Len() if rl.histOffset == 0 { rl.line = []rune(rl.lineBuf) rl.pos = len(rl.lineBuf) } else if rl.histOffset <= -1 { rl.histOffset = 0 + } else if rl.histOffset > historyLen { + // TODO: should this wrap around?s + rl.histOffset = 0 } else { dedup = true old = string(rl.line) - new, err = history.GetLine(history.Len() - rl.histOffset) + new, err = history.GetLine(historyLen - rl.histOffset) if err != nil { rl.resetHelpers() print("\r\n" + err.Error() + "\r\n")