In my app, @codemirror/autocomplete flickers every time a character is typed. I am trying to figure out what options there are for avoiding this, especially because my autocompletion is not even async.
I’ve found update
on CompletionResult but can’t get it work. Digging into the code, I notice this in ActiveResult
:
handleUserEvent(tr: Transaction, type: "input" | "delete", conf: Required<CompletionConfig>): ActiveSource {
let from = tr.changes.mapPos(this.from), to = tr.changes.mapPos(this.to, 1)
let pos = cur(tr.state)
if ((this.explicitPos < 0 ? pos <= from : pos < this.from) ||
pos > to ||
type == "delete" && cur(tr.startState) == this.from)
return new ActiveSource(this.source, type == "input" && conf.activateOnTyping ? State.Pending : State.Inactive)
let explicitPos = this.explicitPos < 0 ? -1 : tr.changes.mapPos(this.explicitPos), updated
if (checkValid(this.result.validFor, tr.state, from, to))
return new ActiveResult(this.source, explicitPos, this.result, from, to)
if (this.result.update &&
(updated = this.result.update(this.result, from, to, new CompletionContext(tr.state, pos, explicitPos >= 0))))
return new ActiveResult(this.source, explicitPos, updated, updated.from, updated.to ?? cur(tr.state))
return new ActiveSource(this.source, State.Pending, explicitPos)
}
This is coded to always remove the autocompletion results unless pos
has increased or explicitPos
is >= zero. It never calls .update(). ExplicitPos is only for explicit activation (which doesn’t apply). When you type another character as part of the same string/token, only to
has increased, so the ActiveResults are discarded and a new query is made.
Update: Rubber ducking strikes again. Seems the issue here was that if you reconfigure the editor extensions while the autocomplete is open, this will cause it to disappear and reappear and make various things go haywire.