Skip to content

Commit c1b7ea4

Browse files
albertxingmarijnh
authored andcommitted
[closebrackets addon] Do not auto-close single apostrophes in comments
Make exception for auto-closing single apostrophes in comments, as per adobe/brackets#3246
1 parent 90209f8 commit c1b7ea4

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

addon/edit/closebrackets.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
if (cm.somethingSelected()) return CodeMirror.Pass;
1818
var cur = cm.getCursor(), line = cm.getLine(cur.line);
1919
if (cur.ch && cur.ch < line.length &&
20-
pairs.indexOf(line.slice(cur.ch - 1, cur.ch + 1)) % 2 == 0)
20+
pairs.indexOf(line.slice(cur.ch - 1, cur.ch + 1)) % 2 == 0)
2121
cm.replaceRange("", CodeMirror.Pos(cur.line, cur.ch - 1), CodeMirror.Pos(cur.line, cur.ch + 1));
2222
else
2323
return CodeMirror.Pass;
@@ -27,15 +27,20 @@
2727
for (var i = 0; i < pairs.length; i += 2) (function(left, right) {
2828
if (left != right) closingBrackets.push(right);
2929
function surround(cm) {
30-
var selection = cm.getSelection();
31-
cm.replaceSelection(left + selection + right);
30+
var selection = cm.getSelection();
31+
cm.replaceSelection(left + selection + right);
3232
}
3333
function maybeOverwrite(cm) {
3434
var cur = cm.getCursor(), ahead = cm.getRange(cur, CodeMirror.Pos(cur.line, cur.ch + 1));
3535
if (ahead != right || cm.somethingSelected()) return CodeMirror.Pass;
3636
else cm.execCommand("goCharRight");
3737
}
3838
map["'" + left + "'"] = function(cm) {
39+
var type = cm.getTokenAt(cm.getCursor()).type;
40+
if (left === "'" && type === "comment") {
41+
cm.replaceSelection("'", {head: ahead, anchor: ahead});
42+
return;
43+
}
3944
if (cm.somethingSelected()) return surround(cm);
4045
if (left == right && maybeOverwrite(cm) != CodeMirror.Pass) return;
4146
var cur = cm.getCursor(), ahead = CodeMirror.Pos(cur.line, cur.ch + 1);

0 commit comments

Comments
 (0)