Is it possible to trigger 'insert snippet' programmatically?
There is a class named InsertSnippetAction but it's never used in the code base.
What we are trying to call is something like this one:
editor.trigger('bla', 'editor.action.insertSnippet', { text: "function {{<function_name>}} ()" });
'editor.action.insertSnippet' is not available in editor.getActions().
@erenbaydemir did you find a way to achieve this?
Did you make it
Did anyone found a way to accomplish this? Inserting by reference/id would be enough for my purposes.
https://microsoft.github.io/monaco-editor/playground.html#extending-language-services-completion-provider-example
@Myqilixiang That's the way to trigger snippets in the editor, I'm looking for a way to do so programmatically. For instance running a snippet with a keyboard shortcut. Or am I missing something?
This worked for me, using monaco-editor-core:
editor.getContribution("snippetController2") returns the SnippetController of the editor.
First set the cursor position, and then call the "insert" method of the snippet controller, first parameter being the template for your snippet in string form.
Still experimenting with this myself, hope it helps.
I would still like a more "official" way to do it though.
Most helpful comment
This worked for me, using monaco-editor-core:
editor.getContribution("snippetController2")returns the SnippetController of the editor.First set the cursor position, and then call the "insert" method of the snippet controller, first parameter being the template for your snippet in string form.
Still experimenting with this myself, hope it helps.
I would still like a more "official" way to do it though.