【问题标题】:Manually adding snippets to react-ace editor手动将片段添加到 react-ace 编辑器
【发布时间】:2018-08-15 17:01:56
【问题描述】:

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

例如,将sn -p myFun添加到javascript

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

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

【问题讨论】:

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


【解决方案1】:

挖源码后,用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

【讨论】:

    猜你喜欢
    • 2014-11-23
    • 1970-01-01
    • 2013-05-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多