mirror of https://github.com/Hilbis/Hilbish
feat: add ctrl delete to forward delete word (#138)
* feat: add ctrl delete to forward delete word (closes #124) * fix: make delete word function accurately * fix: make ctrl delete work on stpull/139/head
parent
1715a1f626
commit
ce625aca0c
|
@ -49,6 +49,8 @@ var (
|
|||
seqEndSc = string([]byte{27, 91, 52, 126})
|
||||
seqDelete = string([]byte{27, 91, 51, 126})
|
||||
seqDelete2 = string([]byte{27, 91, 80})
|
||||
seqCtrlDelete = string([]byte{27, 91, 51, 59, 53, 126})
|
||||
seqCtrlDelete2 = string([]byte{27, 91, 77})
|
||||
seqShiftTab = string([]byte{27, 91, 90})
|
||||
seqAltQuote = string([]byte{27, 34}) // Added for showing registers ^["
|
||||
seqAltR = string([]byte{27, 114}) // Used for alternative history
|
||||
|
|
|
@ -182,3 +182,27 @@ func (rl *Instance) deleteToEnd() {
|
|||
// Keep everything before the cursor
|
||||
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
|
||||
}
|
||||
|
|
|
@ -786,6 +786,19 @@ func (rl *Instance) escapeSeq(r []rune) {
|
|||
rl.viDeleteByAdjust(rl.viJumpB(tokeniseLine))
|
||||
rl.updateHelpers()
|
||||
|
||||
case seqCtrlDelete, seqCtrlDelete2:
|
||||
if rl.modeTabCompletion {
|
||||
rl.resetVirtualComp(false)
|
||||
}
|
||||
// This is only available in Insert mode
|
||||
if rl.modeViMode != VimInsert {
|
||||
return
|
||||
}
|
||||
rl.saveToRegister(rl.emacsForwardWord(tokeniseLine))
|
||||
// vi delete, emacs forward, funny huh
|
||||
rl.viDeleteByAdjust(rl.emacsForwardWord(tokeniseLine))
|
||||
rl.updateHelpers()
|
||||
|
||||
default:
|
||||
if rl.modeTabFind {
|
||||
return
|
||||
|
|
Loading…
Reference in New Issue