ACE编辑器添加了带有新行字符的代码段 [英] ACE Editor adding Snippet with new line character

查看:147
本文介绍了ACE编辑器添加了带有新行字符的代码段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为ACE编辑器添加代码段,我能够通过如下手动添加代码段来实现。

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}){

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

我也尝试过\n,并在编辑器中获得了它,而不是换行符。

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


\ \n

\n


推荐答案

您需要在代码段中的每一行都使用Tab字符缩进,例如

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\
"

这篇关于ACE编辑器添加了带有新行字符的代码段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆