Using apply function in completion interface

Hey there,

I want to change the insert position for a specific completion by changing ‘from’ property.
In v5 it was pretty clear to change it.
In v6, there is apply function for it but it is pretty unclear how to use it.

Is there a chance to get an example? (or perhaps a different method for changing the ‘from’ for a specific completion item).

Thanks :pray:

Changing a completion after the fact isn’t supported. Providing an apply function with your completion allows you to do whatever you want when the completion is picked. You could call insertCompletionText, for example, to insert something where appropriate.

1 Like

Thanks @marijn

Where will I call insertCompletionText ? as apply function?

@marijn tried to use it like that in a completion item:

                apply: (view: EditorView, completion: Completion, from: number, to: number) => {
                    insertCompletionText(view.state, text, from - 2, to);  
                },

I can see that the changes object returned from the function contains the change but the actual value of the editor didn’t changed.

What am I missing?

view.dispatch(insertCompletionText(...))

1 Like

Works like a charm… Thanks!