Skip to content

Commit

Permalink
[closebrackets addon] Do not auto-close single apostrophes in comments
Browse files Browse the repository at this point in the history
Make exception for auto-closing single apostrophes in comments, as per
adobe/brackets#3246
  • Loading branch information
albertxing authored and marijnh committed Apr 3, 2013
1 parent 90209f8 commit c1b7ea4
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions addon/edit/closebrackets.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
if (cm.somethingSelected()) return CodeMirror.Pass;
var cur = cm.getCursor(), line = cm.getLine(cur.line);
if (cur.ch && cur.ch < line.length &&
pairs.indexOf(line.slice(cur.ch - 1, cur.ch + 1)) % 2 == 0)
pairs.indexOf(line.slice(cur.ch - 1, cur.ch + 1)) % 2 == 0)
cm.replaceRange("", CodeMirror.Pos(cur.line, cur.ch - 1), CodeMirror.Pos(cur.line, cur.ch + 1));
else
return CodeMirror.Pass;
Expand All @@ -27,15 +27,20 @@
for (var i = 0; i < pairs.length; i += 2) (function(left, right) {
if (left != right) closingBrackets.push(right);
function surround(cm) {
var selection = cm.getSelection();
cm.replaceSelection(left + selection + right);
var selection = cm.getSelection();
cm.replaceSelection(left + selection + right);
}
function maybeOverwrite(cm) {
var cur = cm.getCursor(), ahead = cm.getRange(cur, CodeMirror.Pos(cur.line, cur.ch + 1));
if (ahead != right || cm.somethingSelected()) return CodeMirror.Pass;
else cm.execCommand("goCharRight");
}
map["'" + left + "'"] = function(cm) {
var type = cm.getTokenAt(cm.getCursor()).type;
if (left === "'" && type === "comment") {
cm.replaceSelection("'", {head: ahead, anchor: ahead});
return;
}
if (cm.somethingSelected()) return surround(cm);
if (left == right && maybeOverwrite(cm) != CodeMirror.Pass) return;
var cur = cm.getCursor(), ahead = CodeMirror.Pos(cur.line, cur.ch + 1);
Expand Down

0 comments on commit c1b7ea4

Please sign in to comment.