thlorenz / brace

📔 browserify compatible version of the ace editor.
http://thlorenz.github.io/brace/
MIT License
1.06k stars 303 forks source link

How do I add custom snippets? #125

Open neopostmodern opened 6 years ago

neopostmodern commented 6 years ago

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?

kmorizur commented 6 years ago

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

hughfenghen commented 5 years ago

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