Skip to content
Browse files

multiline indentation for javascript.

  • Loading branch information...
1 parent 1b150c9 commit 81309264c66962183514d55afcc0bedbab7f5d4d @pydichandra pydichandra committed
Showing with 6 additions and 2 deletions.
  1. +6 −2 mode/javascript/javascript.js
View
8 mode/javascript/javascript.js
@@ -2,6 +2,7 @@
CodeMirror.defineMode("javascript", function(config, parserConfig) {
var indentUnit = config.indentUnit;
+ var statementIndentUnit = config.statementIndentUnit;
var jsonMode = parserConfig.json;
var isTS = parserConfig.typescript;
@@ -227,7 +228,10 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
function pushlex(type, info) {
var result = function() {
var state = cx.state;
- state.lexical = new JSLexical(state.indented, cx.stream.column(), type, null, state.lexical, info);
+ var indent = state.indented;
+ if (state.lexical.type == "stat")
+ indent = state.lexical.indented;
+ state.lexical = new JSLexical(indent, cx.stream.column(), type, null, state.lexical, info);
};
result.lex = true;
return result;
@@ -415,7 +419,7 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
else if (type == "form" && firstChar == "{") return lexical.indented;
else if (type == "form") return lexical.indented + indentUnit;
else if (type == "stat")
- return lexical.indented + (state.lastType == "operator" || state.lastType == "," ? indentUnit : 0);
+ return lexical.indented + (state.lastType == "operator" || state.lastType == "," ? statementIndentUnit : 0);
else if (lexical.info == "switch" && !closing)
return lexical.indented + (/^(?:case|default)\b/.test(textAfter) ? indentUnit : 2 * indentUnit);
else if (lexical.align) return lexical.column + (closing ? 0 : 1);

0 comments on commit 8130926

Please sign in to comment.
Something went wrong with that request. Please try again.