brace icon indicating copy to clipboard operation
brace copied to clipboard

How do I add custom snippets?

Open neopostmodern opened this issue 6 years ago • 2 comments

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?

neopostmodern avatar Apr 25 '18 08:04 neopostmodern

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');`

kmorizur avatar Jun 22 '18 13:06 kmorizur

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

hughfenghen avatar Aug 31 '19 12:08 hughfenghen