Compare commits

..

No commits in common. "1b298fd0d7ae4810f855bd1be173981bb54cb6be" and "f360671e2abf5a21b9a2db7be6f965dcb8530f6f" have entirely different histories.

1 changed files with 13 additions and 31 deletions

View File

@ -18,55 +18,39 @@ func (rl *Instance) insertCandidateVirtual(candidate []rune) {
break
}
// Keep reference of previous candidate to compare its prefix
oldComp := rl.currentComp
// We place the cursor back at the beginning of the previous virtual candidate
rl.pos -= len(oldComp)
rl.pos -= len(rl.currentComp)
// We delete the previous virtual completion, just
// like we would delete a word in vim editing mode.
if len(oldComp) == 1 {
if len(rl.currentComp) == 1 {
rl.deleteVirtual() // Delete a single character
} else if len(oldComp) > 0 {
} else if len(rl.currentComp) > 0 {
rl.viDeleteByAdjustVirtual(rl.viJumpEVirtual(tokeniseSplitSpaces) + 1)
}
prefix := len(rl.tcPrefix)
comp := candidate[prefix:]
// We then keep a reference to the new candidate
rl.currentComp = comp
rl.currentComp = candidate
// We should not have a remaining virtual completion
// line, so it is now identical to the real line.
rl.lineComp = rl.line
compPrefix := candidate[:prefix]
// first clause checks if the previous input wouldve changed the prefix
if (len(oldComp) > 0 && string(oldComp[:prefix]) != rl.tcPrefix) || string(compPrefix) != rl.tcPrefix {
rl.viDeleteByAdjustVirtual(-prefix)
rl.insertVirtual(compPrefix)
}
rl.insertVirtual(comp)
}
func (rl *Instance) insertVirtual(r []rune) {
// we dont need that scuffed unicode fix here, since this function
// is only called in the 2 instances above, which already handles it
// Insert the new candidate in the virtual line.
switch {
case len(rl.lineComp) == 0:
rl.lineComp = r
rl.lineComp = candidate
case rl.pos == 0:
rl.lineComp = append(r, rl.lineComp...)
rl.lineComp = append(candidate, rl.lineComp...)
case rl.pos < len(rl.lineComp):
r := append(r, rl.lineComp[rl.pos:]...)
r := append(candidate, rl.lineComp[rl.pos:]...)
rl.lineComp = append(rl.lineComp[:rl.pos], r...)
default:
rl.lineComp = append(rl.lineComp, r...)
rl.lineComp = append(rl.lineComp, candidate...)
}
// We place the cursor at the end of our new virtually completed item
rl.pos += len(r)
rl.pos += len(candidate)
}
// Insert the current completion candidate into the input line.
@ -129,7 +113,7 @@ func (rl *Instance) updateVirtualComp() {
// Or insert it virtually.
if len(completion) >= prefix {
rl.insertCandidateVirtual([]rune(completion))
rl.insertCandidateVirtual([]rune(completion[prefix:]))
}
}
}
@ -186,14 +170,14 @@ func (rl *Instance) resetVirtualComp(drop bool) {
trimmed = trimmed + " "
}
}
rl.insertCandidateVirtual([]rune(trimmed))
rl.insertCandidateVirtual([]rune(trimmed[prefix:]))
} else {
if rl.compAddSpace {
if !cur.NoSpace {
completion = completion + " "
}
}
rl.insertCandidateVirtual([]rune(completion))
rl.insertCandidateVirtual([]rune(completion[prefix:]))
}
// Reset virtual
@ -290,8 +274,6 @@ func (rl *Instance) deleteVirtual() {
default:
rl.lineComp = append(rl.lineComp[:rl.pos], rl.lineComp[rl.pos+1:]...)
}
rl.pos--
}
// We are done with the current virtual completion candidate.