1

Is it possible to manually add snippets through react-ace component.

For example, adding snippet myFun to javascript:

# Function
snippet myFun
    function ${1?:function_name}(${2:argument}) {
                let x = 'test';
        ${3:// body...}
    } 

I went through the documentation,FAQ ,similar questions here and here.

1

1 Answer 1

2

After digging the source code, it is possible with ace.define(..):

import ace from 'brace';
import snippet from '../lib/json-snippet'

ace.define('ace/snippets/json', ['require', 'exports', 'module'], (e,t,n) => {
  (t.snippetText = snippet), (t.scope = 'json');
});

Snippet example:

const snippet = '# AddNode\n\
snippet addn\n\
    {\n\
        "nodeName": "${1:node_name}",\n\
        "algorithmName": "${2:algo_name}",\n\
        "input": []\n\
    }\n\
';

export default snippet;

Check out a demo here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.