mirror of https://github.com/Hilbis/Hilbish
Compare commits
No commits in common. "1b298fd0d7ae4810f855bd1be173981bb54cb6be" and "f360671e2abf5a21b9a2db7be6f965dcb8530f6f" have entirely different histories.
1b298fd0d7
...
f360671e2a
|
@ -18,55 +18,39 @@ func (rl *Instance) insertCandidateVirtual(candidate []rune) {
|
||||||
break
|
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
|
// 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
|
// We delete the previous virtual completion, just
|
||||||
// like we would delete a word in vim editing mode.
|
// 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
|
rl.deleteVirtual() // Delete a single character
|
||||||
} else if len(oldComp) > 0 {
|
} else if len(rl.currentComp) > 0 {
|
||||||
rl.viDeleteByAdjustVirtual(rl.viJumpEVirtual(tokeniseSplitSpaces) + 1)
|
rl.viDeleteByAdjustVirtual(rl.viJumpEVirtual(tokeniseSplitSpaces) + 1)
|
||||||
}
|
}
|
||||||
prefix := len(rl.tcPrefix)
|
|
||||||
comp := candidate[prefix:]
|
|
||||||
|
|
||||||
// We then keep a reference to the new candidate
|
// We then keep a reference to the new candidate
|
||||||
rl.currentComp = comp
|
rl.currentComp = candidate
|
||||||
|
|
||||||
// We should not have a remaining virtual completion
|
// We should not have a remaining virtual completion
|
||||||
// line, so it is now identical to the real line.
|
// line, so it is now identical to the real line.
|
||||||
rl.lineComp = rl.line
|
rl.lineComp = rl.line
|
||||||
|
|
||||||
compPrefix := candidate[:prefix]
|
// Insert the new candidate in the virtual line.
|
||||||
// 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
|
|
||||||
switch {
|
switch {
|
||||||
case len(rl.lineComp) == 0:
|
case len(rl.lineComp) == 0:
|
||||||
rl.lineComp = r
|
rl.lineComp = candidate
|
||||||
case rl.pos == 0:
|
case rl.pos == 0:
|
||||||
rl.lineComp = append(r, rl.lineComp...)
|
rl.lineComp = append(candidate, rl.lineComp...)
|
||||||
case rl.pos < len(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...)
|
rl.lineComp = append(rl.lineComp[:rl.pos], r...)
|
||||||
default:
|
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
|
// 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.
|
// Insert the current completion candidate into the input line.
|
||||||
|
@ -129,7 +113,7 @@ func (rl *Instance) updateVirtualComp() {
|
||||||
|
|
||||||
// Or insert it virtually.
|
// Or insert it virtually.
|
||||||
if len(completion) >= prefix {
|
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 + " "
|
trimmed = trimmed + " "
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
rl.insertCandidateVirtual([]rune(trimmed))
|
rl.insertCandidateVirtual([]rune(trimmed[prefix:]))
|
||||||
} else {
|
} else {
|
||||||
if rl.compAddSpace {
|
if rl.compAddSpace {
|
||||||
if !cur.NoSpace {
|
if !cur.NoSpace {
|
||||||
completion = completion + " "
|
completion = completion + " "
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
rl.insertCandidateVirtual([]rune(completion))
|
rl.insertCandidateVirtual([]rune(completion[prefix:]))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reset virtual
|
// Reset virtual
|
||||||
|
@ -290,8 +274,6 @@ func (rl *Instance) deleteVirtual() {
|
||||||
default:
|
default:
|
||||||
rl.lineComp = append(rl.lineComp[:rl.pos], rl.lineComp[rl.pos+1:]...)
|
rl.lineComp = append(rl.lineComp[:rl.pos], rl.lineComp[rl.pos+1:]...)
|
||||||
}
|
}
|
||||||
|
|
||||||
rl.pos--
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// We are done with the current virtual completion candidate.
|
// We are done with the current virtual completion candidate.
|
||||||
|
|
Loading…
Reference in New Issue