mirror of https://github.com/Hilbis/Hilbish
fix(readline): make forward delete work properly
parent
722bd1cd80
commit
577f00dfef
|
@ -100,12 +100,12 @@ func moveCursorBackwards(i int) {
|
||||||
printf("\x1b[%dD", i)
|
printf("\x1b[%dD", i)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rl *Instance) backspace() {
|
func (rl *Instance) backspace(forward bool) {
|
||||||
if len(rl.line) == 0 || rl.pos == 0 {
|
if len(rl.line) == 0 || rl.pos == 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
rl.deleteBackspace()
|
rl.deleteBackspace(forward)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rl *Instance) moveCursorByAdjust(adjust int) {
|
func (rl *Instance) moveCursorByAdjust(adjust int) {
|
||||||
|
|
|
@ -125,14 +125,14 @@ func (rl *Instance) deleteX() {
|
||||||
rl.updateHelpers()
|
rl.updateHelpers()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rl *Instance) deleteBackspace() {
|
func (rl *Instance) deleteBackspace(forward bool) {
|
||||||
switch {
|
switch {
|
||||||
case len(rl.line) == 0:
|
case len(rl.line) == 0:
|
||||||
return
|
return
|
||||||
case rl.pos == 0:
|
case forward:
|
||||||
rl.line = rl.line[1:]
|
rl.line = append(rl.line[:rl.pos], rl.line[rl.pos+1:]...)
|
||||||
case rl.pos > len(rl.line):
|
case rl.pos > len(rl.line):
|
||||||
rl.backspace() // There is an infite loop going on here...
|
rl.backspace(forward) // There is an infite loop going on here...
|
||||||
case rl.pos == len(rl.line):
|
case rl.pos == len(rl.line):
|
||||||
rl.pos--
|
rl.pos--
|
||||||
rl.line = rl.line[:rl.pos]
|
rl.line = rl.line[:rl.pos]
|
||||||
|
|
|
@ -214,7 +214,7 @@ func (rl *Instance) Readline() (string, error) {
|
||||||
// Vim mode has different behaviors
|
// Vim mode has different behaviors
|
||||||
if rl.InputMode == Vim {
|
if rl.InputMode == Vim {
|
||||||
if rl.modeViMode == VimInsert {
|
if rl.modeViMode == VimInsert {
|
||||||
rl.backspace()
|
rl.backspace(false)
|
||||||
} else if rl.pos != 0 {
|
} else if rl.pos != 0 {
|
||||||
rl.pos--
|
rl.pos--
|
||||||
}
|
}
|
||||||
|
@ -223,7 +223,7 @@ func (rl *Instance) Readline() (string, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Else emacs deletes a character
|
// Else emacs deletes a character
|
||||||
rl.backspace()
|
rl.backspace(false)
|
||||||
rl.renderHelpers()
|
rl.renderHelpers()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -704,7 +704,7 @@ func (rl *Instance) escapeSeq(r []rune) {
|
||||||
if rl.modeTabFind {
|
if rl.modeTabFind {
|
||||||
rl.backspaceTabFind()
|
rl.backspaceTabFind()
|
||||||
} else {
|
} else {
|
||||||
rl.deleteBackspace()
|
rl.deleteBackspace(true)
|
||||||
}
|
}
|
||||||
case seqHome, seqHomeSc:
|
case seqHome, seqHomeSc:
|
||||||
if rl.modeTabCompletion {
|
if rl.modeTabCompletion {
|
||||||
|
|
Loading…
Reference in New Issue