fix: history navigation going out of bounds

pull/273/merge
sammyette 2024-06-14 08:23:12 -04:00
parent 4c61c551aa
commit 38d036d96f
Signed by: sammyette
GPG Key ID: 904FC49417B44DCD
1 changed files with 5 additions and 1 deletions

View File

@ -128,15 +128,19 @@ func (rl *Instance) walkHistory(i int) {
} }
rl.histOffset += i rl.histOffset += i
historyLen := history.Len()
if rl.histOffset == 0 { if rl.histOffset == 0 {
rl.line = []rune(rl.lineBuf) rl.line = []rune(rl.lineBuf)
rl.pos = len(rl.lineBuf) rl.pos = len(rl.lineBuf)
} else if rl.histOffset <= -1 { } else if rl.histOffset <= -1 {
rl.histOffset = 0 rl.histOffset = 0
} else if rl.histOffset > historyLen {
// TODO: should this wrap around?s
rl.histOffset = 0
} else { } else {
dedup = true dedup = true
old = string(rl.line) old = string(rl.line)
new, err = history.GetLine(history.Len() - rl.histOffset) new, err = history.GetLine(historyLen - rl.histOffset)
if err != nil { if err != nil {
rl.resetHelpers() rl.resetHelpers()
print("\r\n" + err.Error() + "\r\n") print("\r\n" + err.Error() + "\r\n")