fix: make delete word function accurately

ctrl-delete
TorchedSammy 2022-04-12 22:14:41 -04:00
parent ab4fa85c26
commit d3e043ac07
Signed by: sammyette
GPG Key ID: 904FC49417B44DCD
2 changed files with 27 additions and 2 deletions

View File

@ -182,3 +182,27 @@ func (rl *Instance) deleteToEnd() {
// Keep everything before the cursor // Keep everything before the cursor
rl.line = rl.line[:rl.pos] rl.line = rl.line[:rl.pos]
} }
func (rl *Instance) emacsForwardWord(tokeniser tokeniser) (adjust int) {
// when emacs has more specific stuff, move this in a file with then
split, index, pos := tokeniser(rl.line, rl.pos)
if len(split) == 0 {
return
}
word := rTrimWhiteSpace(split[index])
switch {
case len(split) == 0:
return
case index == len(split)-1 && pos >= len(word)-1:
return
case pos >= len(word)-1:
word = rTrimWhiteSpace(split[index+1])
adjust = len(split[index]) - pos
adjust += len(word)
default:
adjust = len(word) - pos
}
return
}

View File

@ -785,8 +785,9 @@ func (rl *Instance) escapeSeq(r []rune) {
if rl.modeViMode != VimInsert { if rl.modeViMode != VimInsert {
return return
} }
rl.saveToRegister(rl.viJumpW(tokeniseLine)) rl.saveToRegister(rl.emacsForwardWord(tokeniseLine))
rl.viDeleteByAdjust(rl.viJumpW(tokeniseLine)) // vi delete, emacs forward, funny huh
rl.viDeleteByAdjust(rl.emacsForwardWord(tokeniseLine))
rl.updateHelpers() rl.updateHelpers()
default: default: