activateOnCompletion not work well

when i used completion.apply。I notice that activateOnCompletion didnt trigger。i read the source code and didnt fix it。here is my code:

completion config:

{
      label: xxx',
      boost: 10,
      apply: (view: EditorView, _: Completion, from: number, to: number) => {
        view.dispatch({
          changes: { from, to, insert: 'xxx' },
          selection: EditorSelection.cursor(from + 3),
          userEvent: 'input.complete',
        });
      },
    }

activateOnCompletion config:

activateOnCompletion: (completion: Completion) => {
          if (completion.label === 'xxx') return true;
          return false;
        },

Include the pickedCompletion effect in your transaction so that the system can recognize it as a completion event (as the docs for apply tell you also).

1 Like

For me it also doesn’t work @marijn – is there anything wrong with this?

return view.dispatch({
    changes: { from, to, insert },
    selection: { anchor: to + insert.length },
    annotations: [pickedCompletion.of(completion)]
});

Moreover, I noticed that the activateOnCompletion is called two times for each completion pick (when using a string for apply).

Update: Adding userEvent: "input.complete" solves the issue.