Autocomplete closes on space which conflicts with validFor pattern

In my editor, there a few tokens that have spaces in them that I want to match against. Here are some example valid tokens:


For the first two, I have a validFor pattern than looks something like /[a-z_]+/i. For the few cases that the tokens have a space in them, I have a regex that looks like this:

/^(?:[a-zA-Z_]+|sort[ by]+)$/i,

I’ve tested the regex and confirmed that it matches sort by, but there seems to be an event that watches space that prevents the validFor from being read and it closes the completion window. I have also tried to pass a dummy function into validFor just to test this (() => true), but that has the same behavior.

I’ve looked through the docs but I didn’t see anything that would allow me to change this behavior. Am I missing something?

I’m not seeing the completions close when I use a source like this:

function source(cx: CompletionContext): CompletionResult {
  return {
    from: cx.pos,
    options: [{label: "sort by"}, {label: "sorta"}],
    validFor: /^(?:[a-zA-Z_]+|sort[ by]+)$/i,

You regexp does look somewhat confused, but that shouldn’t be influencing the matching of “sort by” in this case.

Thanks for confirming this! I had another autocomplete helper plugin that I didn’t realize was interfering with this; once I modified that, it worked as expected.

Your regexp does look somewhat confused

What do you mean?

Well it also matches “sorty yyyyb” etc, but that doesn’t get in the way of the test.