Only uncomment when all lines start with a comment

Previously only the first row was checked for a comment. Now all
rows are checked and the rows are only uncommented when they all
start with a comment.

This only impacts languages that do not specify a command end pattern.

Closes #554
This commit is contained in:
Kevin Sawicki 2013-06-05 17:38:50 -07:00
parent 520e510aab
commit d658e7c490
2 changed files with 25 additions and 0 deletions

View File

@ -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", ->

View File

@ -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))