ACE Editor adding Snippet with new line character

爷,独闯天下 提交于 2020-01-06 17:58:17

问题


I am trying to add snippets for ACE Editor, I was able to achieve that by adding the snippets manually as follows.

ace.define("ace/snippets/c_cpp",["require","exports","module"], 
function(require, exports, module) {
"use strict";

# std::vector\n\
snippet vector\n\
std::vector<${1:T}> ${2};${3}\n\
# std::deque\n\
snippet deque\n\
std::deque<${1:T}> ${2};${3}\n\
...

Everything works well until I add a new line in a snippets, it then doesn't work since the editor is using the new line as a token to separate snippets.

#if\n\
snippet if\n\
if(${1:a}>${2:b}){ \n  } else { }\n\

It then only shows this and stops after the newline. I couldn't find a proper way to use the newline in the snippet.

if(${1:a}>${2:b}){

I also tried \n and got this in the editor instead of a newline.

\n


回答1:


you need to indent every line inside the snippet with a tab character, like this:

exports.snippetText =  "\
snippet cl\n\
\tclass ${1:$FILE_NAME} {\n\
\t\t${2:contents}\n\
\t}\n\
"


来源:https://stackoverflow.com/questions/43891328/ace-editor-adding-snippet-with-new-line-character

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!