Skip to content

Commit

Permalink
[comment addon] Make sure whitespace on empty lines is preserved
Browse files Browse the repository at this point in the history
  • Loading branch information
lukehaas committed May 26, 2022
1 parent e71f684 commit 52b26e8
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion addon/comment/comment.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
var baseString = null;
for (var i = from.line; i < end; ++i) {
var line = self.getLine(i);
var whitespace = line.slice(0, firstNonWS(line));
var whitespace = line.search(nonWS) === -1 ? line : line.slice(0, firstNonWS(line));
if (baseString == null || baseString.length > whitespace.length) {
baseString = whitespace;
}
Expand Down
4 changes: 4 additions & 0 deletions test/comment_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ namespace = "comment_";
cm.lineComment(Pos(1, 0), Pos(2), {indent: true});
}, simpleProg, "function foo() {\n// return bar;\n// }");

test("emptyIndentedLine", "javascript", function(cm) {
cm.lineComment(Pos(1, 2), Pos(1, 2), {indent: true});
}, "function foo() {\n \n}", "function foo() {\n // \n}");

test("singleEmptyLine", "javascript", function(cm) {
cm.setCursor(1);
cm.execCommand("toggleComment");
Expand Down

0 comments on commit 52b26e8

Please sign in to comment.