brace
brace copied to clipboard
How do I add custom snippets?
I tried copying one of the files in brace/snippets/
and loading it from my own sources, but that seems to have no effect.
Also, calling brace.acequire(...)
manually for the defined virtual path is without effect.
Any hints?
Hi,
In order to add your custom snippet (for example for sql mode) you need to :
`const { snippetManager } = ace.acequire('ace/snippets');
const customSnippetText = [ "snippet log", " console.log("${1:}")", "" ].join('\n');
const customSnippet = snippetManager.parseSnippetFile(customSnippetText, 'sql');
snippetManager.register(customSnippet, 'sql');`
Note: snippet content must be start with \t, example:
const customSnippetText = [
'snippet log',
'\tconsole.log("${1:}")',
].join('\n');
Otherwise an error(text.match is not a function) will be thrown when selecting a snippet . Because snippet content is undefined. parseSnippetFile