最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - CodeMirror 2: Multiple indent is deleting lines - Stack Overflow

programmeradmin0浏览0评论

I have implemented Code Mirror as a plugin into a CMS system.

I have an issue where if I select multiple lines and press tab the lines are deleted.

This does not happen on the Code Mirror demo website. I can't find a configuration option to enable or disable multiple indent.

Here is my configuration code:

this.CodeArea = CodeMirror.fromTextArea(codeArea, {
    lineNumbers: true,
    mode: { name: "xml", htmlMode: true },
    onChange : function (editor) {
        editor.save();
    }
});

Context: .Tridion2011Extensions.CodeMirror/BuildingBlocks.Tridion2011Extensions.CodeMirror/Scripts/codemirror/codemirror.js

I'm not sure what I'm missing. Any ideas?

I have implemented Code Mirror as a plugin into a CMS system.

I have an issue where if I select multiple lines and press tab the lines are deleted.

This does not happen on the Code Mirror demo website. I can't find a configuration option to enable or disable multiple indent.

Here is my configuration code:

this.CodeArea = CodeMirror.fromTextArea(codeArea, {
    lineNumbers: true,
    mode: { name: "xml", htmlMode: true },
    onChange : function (editor) {
        editor.save();
    }
});

Context: https://github./rsleggett/tridion-mirror/blob/master/src/BuildingBlocks.Tridion2011Extensions.CodeMirror/BuildingBlocks.Tridion2011Extensions.CodeMirror/Scripts/codemirror/codemirror.js

I'm not sure what I'm missing. Any ideas?

Share Improve this question edited May 24, 2012 at 13:05 Rob Stevenson-Leggett asked May 21, 2012 at 18:03 Rob Stevenson-LeggettRob Stevenson-Leggett 35.7k21 gold badges92 silver badges142 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 13 +200

The CodeMirror javascripts differ between your version and the demo version:

In the demo version at around line 2036 there is the following code block that is missing from your version:

defaultTab: function(cm) {
    if (cm.somethingSelected()) cm.indentSelection("add");
    else cm.replaceSelection("\t", "end");
}

Along with a bunch of functions related to CodeMirror.keyMap.

Compare the two and merge the missing bits, or just use the script from the demo version.

In my case, this was happening because I used the custom snippet from CodeMirror official documentation which mapped the Tab ¡to insert spaces instead of a tab character:

editor.setOption("extraKeys", {
  Tab: function(cm) {
    var spaces = Array(cm.getOption("indentUnit") + 1).join(" ");
    cm.replaceSelection(spaces);
   }
});

Removing this custom snippet made block tabulation work again and spaces were used instead of tabs by default.

发布评论

评论列表(0)

  1. 暂无评论