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

例如,将片段myFun添加到javascript

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


我浏览了文档,常见问题解答,类似的问题herehere

最佳答案

挖掘源代码后,可以使用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

关于javascript - 手动将片段添加到react-ace编辑器,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/51863210/

10-11 12:41