Skip to content

Commit 17f48fb

Browse files
committed
[ruby mode] Fix matching of closing brackets during indentation
Closes #5881
1 parent a86e858 commit 17f48fb

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

mode/ruby/ruby.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ CodeMirror.defineMode("ruby", function(config) {
2828
var indentWords = wordObj(["def", "class", "case", "for", "while", "until", "module", "then",
2929
"catch", "loop", "proc", "begin"]);
3030
var dedentWords = wordObj(["end", "until"]);
31-
var matching = {"[": "]", "{": "}", "(": ")"};
31+
var opening = {"[": "]", "{": "}", "(": ")"};
32+
var closing = {"]": "[", "}": "{", ")": "("};
3233
var curPunc;
3334

3435
function chain(newtok, stream, state) {
@@ -58,7 +59,7 @@ CodeMirror.defineMode("ruby", function(config) {
5859
else if (stream.eat(/[wxq]/)) { style = "string"; embed = false; }
5960
var delim = stream.eat(/[^\w\s=]/);
6061
if (!delim) return "operator";
61-
if (matching.propertyIsEnumerable(delim)) delim = matching[delim];
62+
if (opening.propertyIsEnumerable(delim)) delim = opening[delim];
6263
return chain(readQuoted(delim, style, embed, true), stream, state);
6364
} else if (ch == "#") {
6465
stream.skipToEnd();
@@ -280,9 +281,9 @@ CodeMirror.defineMode("ruby", function(config) {
280281
if (state.tokenize[state.tokenize.length-1] != tokenBase) return CodeMirror.Pass;
281282
var firstChar = textAfter && textAfter.charAt(0);
282283
var ct = state.context;
283-
var closing = ct.type == matching[firstChar] ||
284+
var closed = ct.type == closing[firstChar] ||
284285
ct.type == "keyword" && /^(?:end|until|else|elsif|when|rescue)\b/.test(textAfter);
285-
return ct.indented + (closing ? 0 : config.indentUnit) +
286+
return ct.indented + (closed ? 0 : config.indentUnit) +
286287
(state.continuedLine ? config.indentUnit : 0);
287288
},
288289

0 commit comments

Comments
 (0)