简体   繁体   English

如何在不使用“ [”的情况下使用Codemirror代码折叠?

[英]How to use Codemirror codefolding without “[”?

I would like to use Codemirror codefolding to fold just { and } as well as comments. 我想用Codemirror语法折叠只折叠{}以及评论。 The only problem I am having is it also codefolds the brackets [ and ] . 我唯一的问题是它也会将括号[]折叠。 The square brackets are almost always part of one line statements and I do not wish to use codefolding for them. 方括号几乎总是一行语句的一部分,我不希望使用语法折叠他们。 How can I prevent that? 我该如何预防?

In codemirror/addon/fold/brace-fold.js I tried commenting out these lines: codemirror/addon/fold/brace-fold.js我试图注释出这些行:

if (startCh == null) {
    startToken = "[", endToken = "]";
    startCh = findOpening("[");
  }

but that still does not prevent codefolding for square brackets. 但这仍然不能防止方括号的代码折叠。 Also, any ideas what addon/fold/indent-fold.js does? 此外,任何想法什么addon/fold/indent-fold.js呢? I am not sure whether I should include that file. 我不知道我是否应包含该文件。

NB I am using Codefolding for both JavaScript and PHP modes. NB我使用的语法折叠的JavaScript和PHP模式。

EDIT 编辑

Here's a demonstration of Codemirror codefolding . 下面是一个示范Codemirror语法折叠

The OP code is just fine. OP代码就可以了。

According to comments the problem was coming from a cached version of the file, making the modification seem like they are not working. 根据评论,该问题来自文件的缓存版本,使修改似乎不起作用。

To prevent this kind of problem in the futur, note that hitting F5 will not clear cache. 为了防止这种在未来的危机问题,注意按F5不会清除缓存。 You need to use ctrl+F5. 您需要使用ctrl + F5。 Another good option I use is in the developer tools (I use Chrome but it is certainly there in other browsers too), you can set the browser to clear cache whenever the devtools is open. 我使用的另一个不错的选择是在开发人员工具中(我使用的是Chrome,但其他浏览器中也有),您可以将浏览器设置为在打开devtools时清除缓存。 Since the tab is almost always open when testing your website, this makes cache problems never happen... 由于测试您的网站时该选项卡几乎始终处于打开状态,因此使缓存问题永远不会发生...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM