Skip to content

Commit 26b739f

Browse files
committed
[comment addon] Keep selection in front of closing marker when block-commenting
... with fullLines==false when the end of the selection is directly on the closing marker. Closes codemirror#6375
1 parent fd3e439 commit 26b739f

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

addon/comment/comment.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
var noOptions = {};
1515
var nonWS = /[^\s\u00a0]/;
16-
var Pos = CodeMirror.Pos;
16+
var Pos = CodeMirror.Pos, cmp = CodeMirror.cmpPos;
1717

1818
function firstNonWS(str) {
1919
var found = str.search(nonWS);
@@ -126,7 +126,9 @@
126126
if (i != end || lastLineHasText)
127127
self.replaceRange(lead + pad, Pos(i, 0));
128128
} else {
129+
var atCursor = cmp(self.getCursor("to"), to) == 0, empty = !self.somethingSelected()
129130
self.replaceRange(endString, to);
131+
if (atCursor) self.setSelection(empty ? to : self.getCursor("from"), to)
130132
self.replaceRange(startString, from);
131133
}
132134
});

0 commit comments

Comments
 (0)