In monaco I can define autocomplete which inserts text with highlighted place holders, and when hitting the tab key it moves on to the next place holder,
For example, I define the following language on monaco:
monaco.languages.register({ id: 'mySpecialLanguage' });
// Register a completion item provider for the new language
monaco.languages.registerCompletionItemProvider('mySpecialLanguage', {
provideCompletionItems: () => {
var suggestions = [
{
label: 'if',
kind: monaco.languages.CompletionItemKind.Keyword,
insertText: 'if(${1:logical_expression}, ${2:value_if_true}, ${3:value_if_false})',
insertTextRules: monaco.languages.CompletionItemInsertTextRule.InsertAsSnippet
}
];
return { suggestions: suggestions };
}
});
monaco.editor.create(document.getElementById('container'), {
language: 'mySpecialLanguage'
});
I'm running above on the playground and this is the result when typing 'if' and hitting tab:
if I hit the tab the focused area moves from logical_expression to value_if_true, if I type on the keyboard text is inserted in the focused area.
attaching screen recording:
Now I'm trying to insert text from an outside event (not via builtin CompletionItem) with the same behaviour as in the CompletionItem.
Text inserted: if(logical_expression, value_if_true, value_if_false) with placeholders highlighted and enable moving with tabs to focus on placeholders.
I tried the following
monaco.editor.trigger('keyboard', 'type', {
text: 'if(${1:logical_expression}, ${2:value_if_true}, ${3:value_if_false})',
kind: monaco.languages.CompletionItemKind.Keyword,
insertTextRules: monaco.languages.CompletionItemInsertTextRule.InsertAsSnippet,
});
but this inserts the text as plain text without desired behaviour.
How can I achieve above behaviour - similar to the autocomplete behaviour
