diff --git a/addon/comment/comment.js b/addon/comment/comment.js index 2dd114d332dc9b1e0b19cfff3fc60061c7cb9fbe..1c7aaae1e17a594c9f883465aed1c9af85fc92a2 100644 --- a/addon/comment/comment.js +++ b/addon/comment/comment.js @@ -57,7 +57,14 @@ self.operation(function() { if (options.indent) { - var baseString = firstLine.slice(0, firstNonWS(firstLine)); + var baseString = null; + for (var i = from.line; i < end; ++i) { + var line = self.getLine(i); + var whitespace = line.slice(0, firstNonWS(line)); + if (baseString == null || baseString.length > whitespace.length) { + baseString = whitespace; + } + } for (var i = from.line; i < end; ++i) { var line = self.getLine(i), cut = baseString.length; if (!blankLines && !nonWS.test(line)) continue; diff --git a/test/comment_test.js b/test/comment_test.js index 8bd3959ee92a3b452fd9380ca9a9a62d7dd78d4d..26e474493b19c5ef99714bdfa48de28bb82693f9 100644 --- a/test/comment_test.js +++ b/test/comment_test.js @@ -79,7 +79,7 @@ namespace = "comment_"; test("indented", "javascript", function(cm) { cm.lineComment(Pos(1, 0), Pos(2), {indent: true}); - }, simpleProg, "function foo() {\n // return bar;\n // }"); + }, simpleProg, "function foo() {\n// return bar;\n// }"); test("singleEmptyLine", "javascript", function(cm) { cm.setCursor(1);