mirror of https://github.com/Hilbis/Hilbish
fix: provide correct command when navigating history
previously, the order while navigating history with the arrow keys would be incorrect meaning the command you expect if you go u then go back down would not be therehistory-navigation-fix
parent
06102ebdae
commit
9e4ef0483b
|
@ -123,23 +123,20 @@ func (rl *Instance) walkHistory(i int) {
|
||||||
|
|
||||||
// When we are exiting the current line buffer to move around
|
// When we are exiting the current line buffer to move around
|
||||||
// the history, we make buffer the current line
|
// the history, we make buffer the current line
|
||||||
if rl.histPos == 0 && (rl.histPos+i) == 1 {
|
if rl.histOffset == 0 && rl.histOffset + i == 1 {
|
||||||
rl.lineBuf = string(rl.line)
|
rl.lineBuf = string(rl.line)
|
||||||
}
|
}
|
||||||
|
|
||||||
switch rl.histPos + i {
|
rl.histOffset += i
|
||||||
case 0, history.Len() + 1:
|
if rl.histOffset == 0 {
|
||||||
rl.histPos = 0
|
|
||||||
rl.line = []rune(rl.lineBuf)
|
rl.line = []rune(rl.lineBuf)
|
||||||
rl.pos = len(rl.lineBuf)
|
rl.pos = len(rl.lineBuf)
|
||||||
return
|
} else if rl.histOffset <= -1 {
|
||||||
case -1:
|
rl.histOffset = 0
|
||||||
rl.histPos = 0
|
} else {
|
||||||
rl.lineBuf = string(rl.line)
|
|
||||||
default:
|
|
||||||
dedup = true
|
dedup = true
|
||||||
old = string(rl.line)
|
old = string(rl.line)
|
||||||
new, err = history.GetLine(history.Len() - rl.histPos - 1)
|
new, err = history.GetLine(history.Len() - 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")
|
||||||
|
@ -148,7 +145,6 @@ func (rl *Instance) walkHistory(i int) {
|
||||||
}
|
}
|
||||||
|
|
||||||
rl.clearLine()
|
rl.clearLine()
|
||||||
rl.histPos += i
|
|
||||||
rl.line = []rune(new)
|
rl.line = []rune(new)
|
||||||
rl.pos = len(rl.line)
|
rl.pos = len(rl.line)
|
||||||
if rl.pos > 0 {
|
if rl.pos > 0 {
|
||||||
|
|
|
@ -134,6 +134,7 @@ type Instance struct {
|
||||||
// history operating params
|
// history operating params
|
||||||
lineBuf string
|
lineBuf string
|
||||||
histPos int
|
histPos int
|
||||||
|
histOffset int
|
||||||
histNavIdx int // Used for quick history navigation.
|
histNavIdx int // Used for quick history navigation.
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
|
@ -49,7 +49,7 @@ func (rl *Instance) Readline() (string, error) {
|
||||||
|
|
||||||
// History Init
|
// History Init
|
||||||
// We need this set to the last command, so that we can access it quickly
|
// We need this set to the last command, so that we can access it quickly
|
||||||
rl.histPos = 0
|
rl.histOffset = 0
|
||||||
rl.viUndoHistory = []undoItem{{line: "", pos: 0}}
|
rl.viUndoHistory = []undoItem{{line: "", pos: 0}}
|
||||||
|
|
||||||
// Multisplit
|
// Multisplit
|
||||||
|
|
Loading…
Reference in New Issue