Skip to content

Commit

Permalink
multiline indentation for javascript.
Browse files Browse the repository at this point in the history
  • Loading branch information
pydichandra committed Mar 28, 2013
1 parent 56def7d commit 02f5cfb
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions mode/javascript/javascript.js
Expand Up @@ -2,6 +2,7 @@

CodeMirror.defineMode("javascript", function(config, parserConfig) {
var indentUnit = config.indentUnit;
var statementIndentUnit = parserConfig.statementIndentUnit || indentUnit;
var jsonMode = parserConfig.json;
var isTS = parserConfig.typescript;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 02f5cfb

Please sign in to comment.