I want to start autocompletion after user type a @
character, which will open a tooltip box with a username list.
I have to define a regex like /(^@[\w]*$)|((?<=\s)@[\w]*$)/
(@
must in the beginning or there is a whitespace before @
)
But the regex is also used in completion source options filter, so the option label text also need start with @
.
I hope the label text is a pure username without redundant @
.
Currently, I return a completion source with from: word.from + 1
to match the remaining token after @
.
It works, but the workaround got another problem. Backspace to the beginning @
will not open tooltip.
@
=> tooltip with init options
@x
=> tooltip with filtered options
Then I press Backspace
to delete chars until @
@
=> none tooltip opened.
function completionSource(context) {
let word = context.matchBefore(regex);
if (word == null) {
return null;
}
return {
from: word.from + 1,
options,
// validFor: regexValidFor,
};
}