Skip to content

Commit

Permalink
Make sure indent is always passed three arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
marijnh committed Jan 10, 2019
1 parent 12f8159 commit 0e80400
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 21 deletions.
8 changes: 4 additions & 4 deletions addon/mode/multiplex.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ CodeMirror.multiplexingMode = function(outer /*, others */) {
// Get the outer indent, making sure to handle CodeMirror.Pass
var outerIndent = 0;
if (outer.indent) {
var possibleOuterIndent = outer.indent(state.outer, "");
var possibleOuterIndent = outer.indent(state.outer, "", "");
if (possibleOuterIndent !== CodeMirror.Pass) outerIndent = possibleOuterIndent;
}

Expand Down Expand Up @@ -96,10 +96,10 @@ CodeMirror.multiplexingMode = function(outer /*, others */) {
}
},

indent: function(state, textAfter) {
indent: function(state, textAfter, line) {
var mode = state.innerActive ? state.innerActive.mode : outer;
if (!mode.indent) return CodeMirror.Pass;
return mode.indent(state.innerActive ? state.inner : state.outer, textAfter);
return mode.indent(state.innerActive ? state.inner : state.outer, textAfter, line);
},

blankLine: function(state) {
Expand All @@ -112,7 +112,7 @@ CodeMirror.multiplexingMode = function(outer /*, others */) {
var other = others[i];
if (other.open === "\n") {
state.innerActive = other;
state.inner = CodeMirror.startState(other.mode, mode.indent ? mode.indent(state.outer, "") : 0);
state.inner = CodeMirror.startState(other.mode, mode.indent ? mode.indent(state.outer, "", "") : 0);
}
}
} else if (state.innerActive.close === "\n") {
Expand Down
4 changes: 2 additions & 2 deletions addon/mode/overlay.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ CodeMirror.overlayMode = function(base, overlay, combine) {
else return state.overlayCur;
},

indent: base.indent && function(state, textAfter) {
return base.indent(state.base, textAfter);
indent: base.indent && function(state, textAfter, line) {
return base.indent(state.base, textAfter, line);
},
electricChars: base.electricChars,

Expand Down
4 changes: 2 additions & 2 deletions mode/htmlmixed/htmlmixed.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
return maybeBackup(stream, endTag, state.localMode.token(stream, state.localState));
};
state.localMode = mode;
state.localState = CodeMirror.startState(mode, htmlMode.indent(state.htmlState, ""));
state.localState = CodeMirror.startState(mode, htmlMode.indent(state.htmlState, "", ""));
} else if (state.inTag) {
state.inTag += stream.current()
if (stream.eol()) state.inTag += " "
Expand Down Expand Up @@ -135,7 +135,7 @@

indent: function (state, textAfter, line) {
if (!state.localMode || /^\s*<\//.test(textAfter))
return htmlMode.indent(state.htmlState, textAfter);
return htmlMode.indent(state.htmlState, textAfter, line);
else if (state.localMode.indent)
return state.localMode.indent(state.localState, textAfter, line);
else
Expand Down
4 changes: 2 additions & 2 deletions mode/jsx/jsx.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
function flatXMLIndent(state) {
var tagName = state.tagName
state.tagName = null
var result = xmlMode.indent(state, "")
var result = xmlMode.indent(state, "", "")
state.tagName = tagName
return result
}
Expand Down Expand Up @@ -105,7 +105,7 @@
function jsToken(stream, state, cx) {
if (stream.peek() == "<" && jsMode.expressionAllowed(stream, cx.state)) {
jsMode.skipExpression(cx.state)
state.context = new Context(CodeMirror.startState(xmlMode, jsMode.indent(cx.state, "")),
state.context = new Context(CodeMirror.startState(xmlMode, jsMode.indent(cx.state, "", "")),
xmlMode, 0, state.context)
return null
}
Expand Down
8 changes: 4 additions & 4 deletions mode/php/php.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@
if (!isPHP) {
if (stream.match(/^<\?\w*/)) {
state.curMode = phpMode;
if (!state.php) state.php = CodeMirror.startState(phpMode, htmlMode.indent(state.html, ""))
if (!state.php) state.php = CodeMirror.startState(phpMode, htmlMode.indent(state.html, "", ""))
state.curState = state.php;
return "meta";
}
Expand Down Expand Up @@ -213,11 +213,11 @@

token: dispatch,

indent: function(state, textAfter) {
indent: function(state, textAfter, line) {
if ((state.curMode != phpMode && /^\s*<\//.test(textAfter)) ||
(state.curMode == phpMode && /^\?>/.test(textAfter)))
return htmlMode.indent(state.html, textAfter);
return state.curMode.indent(state.curState, textAfter);
return htmlMode.indent(state.html, textAfter, line);
return state.curMode.indent(state.curState, textAfter, line);
},

blockCommentStart: "/*",
Expand Down
4 changes: 2 additions & 2 deletions mode/smarty/smarty.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,9 @@
state.last = last;
return style;
},
indent: function(state, text) {
indent: function(state, text, line) {
if (state.tokenize == tokenTop && baseMode.indent)
return baseMode.indent(state.base, text);
return baseMode.indent(state.base, text, line);
else
return CodeMirror.Pass;
},
Expand Down
8 changes: 4 additions & 4 deletions mode/soy/soy.js
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@
var mode = modes[kind] || modes.html;
var localState = last(state.localStates);
if (localState.mode.indent) {
state.indent += localState.mode.indent(localState.state, "");
state.indent += localState.mode.indent(localState.state, "", "");
}
state.localStates.push({
mode: mode,
Expand Down Expand Up @@ -310,7 +310,7 @@
state.localStates.pop();
var localState = last(state.localStates);
if (localState.mode.indent) {
state.indent -= localState.mode.indent(localState.state, "");
state.indent -= localState.mode.indent(localState.state, "", "");
}
}
state.soyState.push("tag");
Expand Down Expand Up @@ -346,7 +346,7 @@
return tokenUntil(stream, state, /\{|\s+\/\/|\/\*/);
},

indent: function(state, textAfter) {
indent: function(state, textAfter, line) {
var indent = state.indent, top = last(state.soyState);
if (top == "comment") return CodeMirror.Pass;

Expand All @@ -360,7 +360,7 @@
}
var localState = last(state.localStates);
if (indent && localState.mode.indent) {
indent += localState.mode.indent(localState.state, textAfter);
indent += localState.mode.indent(localState.state, textAfter, line);
}
return indent;
},
Expand Down
2 changes: 1 addition & 1 deletion test/mode_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@
var line = lines[i], newLine = true;
if (mode.indent) {
var ws = line.match(/^\s*/)[0];
var indent = mode.indent(state, line.slice(ws.length));
var indent = mode.indent(state, line.slice(ws.length), line);
if (indent != CodeMirror.Pass && indent != ws.length)
(st.indentFailures || (st.indentFailures = [])).push(
"Indentation of line " + (i + 1) + " is " + indent + " (expected " + ws.length + ")");
Expand Down

0 comments on commit 0e80400

Please sign in to comment.