手动将片段添加到react-ace编辑器

时间:2018-08-15 17:01:56

标签: javascript code-snippets ace-editor react-ace

是否可以通过react-ace组件手动添加摘要。

例如,将片段myFun添加到javascript

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

我仔细阅读了文档,常见问题解答,类似问题herehere

1 个答案:

答案 0 :(得分:0)

在挖掘源代码之后,可以使用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');
});

代码段示例:

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

export default snippet;

查看演示here

相关问题