Skip to content

Commit b4ec855

Browse files
committed
[clike mode] Fix comma behavior
And fix another bug introduced by 329b9e6 Closes #4310
1 parent 09594e2 commit b4ec855

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

mode/clike/clike.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ function Context(indented, column, type, info, align, prev) {
2121
}
2222
function pushContext(state, col, type, info) {
2323
var indent = state.indented;
24-
if (state.context && state.context.type != "statement" && type != "statement")
24+
if (state.context && state.context.type == "statement" && type != "statement")
2525
indent = state.context.indented;
2626
return state.context = new Context(indent, col, type, info, null, state.context);
2727
}
@@ -64,8 +64,7 @@ CodeMirror.defineMode("clike", function(config, parserConfig) {
6464
isPunctuationChar = parserConfig.isPunctuationChar || /[\[\]{}\(\),;\:\.]/,
6565
numberStart = parserConfig.numberStart || /[\d\.]/,
6666
number = parserConfig.number || /^(?:0x[a-f\d]+|0b[01]+|(?:\d+\.?\d*|\.\d+)(?:e[-+]?\d+)?)(u|ll?|l|f)?/i,
67-
isOperatorChar = parserConfig.isOperatorChar || /[+\-*&%=<>!?|\/]/,
68-
endStatement = parserConfig.endStatement || /^[;:,]$/;
67+
isOperatorChar = parserConfig.isOperatorChar || /[+\-*&%=<>!?|\/]/;
6968

7069
var curPunc, isDefKeyword;
7170

@@ -177,7 +176,8 @@ CodeMirror.defineMode("clike", function(config, parserConfig) {
177176
if (style == "comment" || style == "meta") return style;
178177
if (ctx.align == null) ctx.align = true;
179178

180-
if (endStatement.test(curPunc)) while (state.context.type == "statement") popContext(state);
179+
if (curPunc == ";" || curPunc == ":" || (curPunc == "," && stream.match(/^\s*(?:\/\/.*)?$/, false)))
180+
while (state.context.type == "statement") popContext(state);
181181
else if (curPunc == "{") pushContext(state, stream.column(), "}");
182182
else if (curPunc == "[") pushContext(state, stream.column(), "]");
183183
else if (curPunc == "(") pushContext(state, stream.column(), ")");
@@ -432,7 +432,6 @@ CodeMirror.defineMode("clike", function(config, parserConfig) {
432432
defKeywords: words("class interface package enum"),
433433
typeFirstDefinitions: true,
434434
atoms: words("true false null"),
435-
endStatement: /^[;:]$/,
436435
number: /^(?:0x[a-f\d_]+|0b[01_]+|(?:[\d_]+\.?\d*|\.\d+)(?:e[-+]?[\d_]+)?)(u|ll?|l|f)?/i,
437436
hooks: {
438437
"@": function(stream) {

0 commit comments

Comments
 (0)