CodeMirror 2: multiple indentation removes lines

I implemented Code Mirror as a plugin in the CMS system.

I have a problem, if I select multiple lines and click on the tab, the lines are deleted.

This does not happen on the Code Mirror demo site. I cannot find a configuration option to enable or disable multiple indentation.

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.com/rsleggett/tridion-mirror/blob/master/src/BuildingBlocks.Tridion2011Extensions.CodeMirror/BuildingBlocks.Tridion2011Extensions.CodeMirror/Scripts/codemirror/codemirror.js

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

+7
source share
2 answers

CodeMirror JavaScript codes are different for your version and demo :

In the demo version, near line 2036, there is the following code that is missing from your version:

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

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

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

+11
source

In my case, this happened because I used my own fragment from the official CodeMirror documentation, which displayed 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 by a block tabulator works again, and by default spaces were used instead of tabs.

0
source

All Articles