Skip to content
Snippets Groups Projects
Commit fbefd524 authored by Marijn Haverbeke's avatar Marijn Haverbeke
Browse files

[xml mode] Fix indentation bug when attributes are contd on indented line

Closes #1366
parent 037993fb
No related branches found
No related tags found
No related merge requests found
......@@ -165,7 +165,7 @@ CodeMirror.defineMode("xml", function(config, parserConfig) {
};
}
var curState, setStyle;
var curState, curStream, setStyle;
function pass() {
for (var i = arguments.length - 1; i >= 0; i--) curState.cc.push(arguments[i]);
}
......@@ -191,6 +191,7 @@ CodeMirror.defineMode("xml", function(config, parserConfig) {
function element(type) {
if (type == "openTag") {
curState.tagName = tagName;
curState.tagStart = curStream.column();
return cont(attributes, endtag(curState.startOfLine));
} else if (type == "closeTag") {
var err = false;
......@@ -212,7 +213,7 @@ CodeMirror.defineMode("xml", function(config, parserConfig) {
function endtag(startOfLine) {
return function(type) {
var tagName = curState.tagName;
curState.tagName = null;
curState.tagName = curState.tagStart = null;
if (type == "selfcloseTag" ||
(type == "endTag" && Kludges.autoSelfClosers.hasOwnProperty(tagName.toLowerCase()))) {
maybePopContext(tagName.toLowerCase());
......@@ -274,11 +275,11 @@ CodeMirror.defineMode("xml", function(config, parserConfig) {
return {
startState: function() {
return {tokenize: inText, cc: [], indented: 0, startOfLine: true, tagName: null, context: null};
return {tokenize: inText, cc: [], indented: 0, startOfLine: true, tagName: null, tagStart: null, context: null};
},
token: function(stream, state) {
if (stream.sol()) {
if (!state.tagName && stream.sol()) {
state.startOfLine = true;
state.indented = stream.indentation();
}
......@@ -288,7 +289,7 @@ CodeMirror.defineMode("xml", function(config, parserConfig) {
var style = state.tokenize(stream, state);
state.type = type;
if ((style || type) && style != "comment") {
curState = state;
curState = state; curStream = stream;
while (true) {
var comb = state.cc.pop() || element;
if (comb(type || style)) break;
......@@ -303,6 +304,7 @@ CodeMirror.defineMode("xml", function(config, parserConfig) {
if ((state.tokenize != inTag && state.tokenize != inText) ||
context && context.noIndent)
return fullLine ? fullLine.match(/^(\s*)/)[0].length : 0;
if (state.tagName) return state.tagStart + indentUnit;
if (alignCDATA && /<!\[CDATA\[/.test(textAfter)) return 0;
if (context && /^<\//.test(textAfter))
context = context.prev;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment