mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2024-11-13 08:44:12 +03:00
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:
parent
520e510aab
commit
d658e7c490
@ -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", ->
|
||||
|
@ -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))
|
||||
|
Loading…
Reference in New Issue
Block a user