Skip to content

Commit 894db1e

Browse files
committed
Make XML mode autoindent preserve space in CDATA and PRE blocks
1 parent 568fe4a commit 894db1e

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

lib/codemirror.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1149,7 +1149,7 @@ var CodeMirror = (function() {
11491149
if (n) indentation = getLine(n-1).indentation(options.tabSize);
11501150
else indentation = 0;
11511151
}
1152-
else if (how == "smart") indentation = mode.indent(state, line.text.slice(curSpaceString.length));
1152+
else if (how == "smart") indentation = mode.indent(state, line.text.slice(curSpaceString.length), line.text);
11531153
else if (how == "add") indentation = curSpace + options.indentUnit;
11541154
else if (how == "subtract") indentation = curSpace - options.indentUnit;
11551155
indentation = Math.max(0, indentation);

mode/xml/xml.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,9 +226,10 @@ CodeMirror.defineMode("xml", function(config, parserConfig) {
226226
return setStyle || style;
227227
},
228228

229-
indent: function(state, textAfter) {
229+
indent: function(state, textAfter, fullLine) {
230230
var context = state.context;
231-
if (context && context.noIndent) return 0;
231+
if (context && context.noIndent)
232+
return fullLine ? fullLine.match(/^(\s*)/)[0].length : 0;
232233
if (alignCDATA && /<!\[CDATA\[/.test(textAfter)) return 0;
233234
if (context && /^<\//.test(textAfter))
234235
context = context.prev;

0 commit comments

Comments
 (0)