Skip to content

Commit e338ab2

Browse files
AlexanderPrendotamarijnh
authored andcommitted
[clike] update kotlin indents
1 parent 91f3711 commit e338ab2

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

mode/clike/clike.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,15 +216,15 @@ CodeMirror.defineMode("clike", function(config, parserConfig) {
216216
indent: function(state, textAfter) {
217217
if (state.tokenize != tokenBase && state.tokenize != null || state.typeAtEndOfLine) return CodeMirror.Pass;
218218
var ctx = state.context, firstChar = textAfter && textAfter.charAt(0);
219+
var closing = firstChar == ctx.type;
219220
if (ctx.type == "statement" && firstChar == "}") ctx = ctx.prev;
220221
if (parserConfig.dontIndentStatements)
221222
while (ctx.type == "statement" && parserConfig.dontIndentStatements.test(ctx.info))
222223
ctx = ctx.prev
223224
if (hooks.indent) {
224-
var hook = hooks.indent(state, ctx, textAfter);
225+
var hook = hooks.indent(state, ctx, textAfter, indentUnit, closing);
225226
if (typeof hook == "number") return hook
226227
}
227-
var closing = firstChar == ctx.type;
228228
var switchBlock = ctx.prev && ctx.prev.info == "switch";
229229
if (parserConfig.allmanIndentation && /[{(]/.test(firstChar)) {
230230
while (ctx.type != "top" && ctx.type != "}") ctx = ctx.prev
@@ -631,6 +631,17 @@ CodeMirror.defineMode("clike", function(config, parserConfig) {
631631
'"': function(stream, state) {
632632
state.tokenize = tokenKotlinString(stream.match('""'));
633633
return state.tokenize(stream, state);
634+
},
635+
indent: function(state, ctx, textAfter, indentUnit, closing) {
636+
var firstChar = textAfter && textAfter.charAt(0);
637+
if ((state.prevToken == "}" || state.prevToken == ")") && textAfter == "")
638+
return state.indented;
639+
if (state.prevToken == "operator" && textAfter != "}" ||
640+
state.prevToken == "variable" && firstChar == "." ||
641+
(state.prevToken == "}" || state.prevToken == ")") && firstChar == ".")
642+
return indentUnit * 2 + ctx.indented;
643+
if (ctx.align && ctx.type == "}")
644+
return ctx.indented + (closing ? 0 : indentUnit);
634645
}
635646
},
636647
modeProps: {closeBrackets: {triples: '"'}}

0 commit comments

Comments
 (0)