diff --git a/spec/app/language-mode-spec.coffee b/spec/app/language-mode-spec.coffee index adcd9b868..08a37fca7 100644 --- a/spec/app/language-mode-spec.coffee +++ b/spec/app/language-mode-spec.coffee @@ -28,6 +28,27 @@ describe "LanguageMode", -> expect(buffer.lineForRow(6)).toBe "// current < pivot ? left.push(current) : right.push(current);" expect(buffer.lineForRow(7)).toBe "// }" + it "only uncomments lines if all lines start with a comment", -> + languageMode.toggleLineCommentsForBufferRows(0, 0) + expect(buffer.lineForRow(0)).toBe "// var quicksort = function () {" + + languageMode.toggleLineCommentsForBufferRows(0, 2) + expect(buffer.lineForRow(0)).toBe "// // var quicksort = function () {" + expect(buffer.lineForRow(1)).toBe "// var sort = function(items) {" + expect(buffer.lineForRow(2)).toBe "// if (items.length <= 1) return items;" + + it "uncomments commented lines separated by an empty line", -> + languageMode.toggleLineCommentsForBufferRows(0, 1) + expect(buffer.lineForRow(0)).toBe "// var quicksort = function () {" + expect(buffer.lineForRow(1)).toBe "// var sort = function(items) {" + + buffer.insert([0, Infinity], '\n') + + languageMode.toggleLineCommentsForBufferRows(0, 2) + expect(buffer.lineForRow(0)).toBe "var quicksort = function () {" + expect(buffer.lineForRow(1)).toBe "" + expect(buffer.lineForRow(2)).toBe " var sort = function(items) {" + describe "fold suggestion", -> describe ".doesBufferRowStartFold(bufferRow)", -> it "returns true only when the buffer row starts a foldable region", -> diff --git a/src/app/language-mode.coffee b/src/app/language-mode.coffee index ad1965fe8..b3cfb1ec9 100644 --- a/src/app/language-mode.coffee +++ b/src/app/language-mode.coffee @@ -64,6 +64,10 @@ class LanguageMode buffer.insert([start, 0], commentStartString) buffer.insert([end, buffer.lineLengthForRow(end)], commentEndString) else + if shouldUncomment and start isnt end + shouldUncomment = [start+1..end].every (row) -> + line = buffer.lineForRow(row) + not line or commentStartRegex.test(line) if shouldUncomment for row in [start..end] if match = commentStartRegex.search(buffer.lineForRow(row))