mirror of
https://github.com/atom/atom.git
synced 2026-01-23 13:58:08 -05:00
When uncommenting multiple lines, don't raise an error if a line isn't commented
Previously, we were assuming that when uncommenting, that every line would match the comment regex. But this might not be the case. If the first line in the selection is commented but some subsequent lines aren't, they won't match the comment regex. So this commit guards for that case.
This commit is contained in:
@@ -1323,6 +1323,25 @@ describe "EditSession", ->
|
||||
expect(buffer.lineForRow(6)).toBe " current < pivot ? left.push(current) : right.push(current);"
|
||||
expect(buffer.lineForRow(7)).toBe " }"
|
||||
|
||||
it "uncomments lines if the first line matches the comment regex", ->
|
||||
editSession.setSelectedBufferRange([[4, 5], [4, 5]])
|
||||
editSession.toggleLineCommentsInSelection()
|
||||
editSession.setSelectedBufferRange([[6, 5], [6, 5]])
|
||||
editSession.toggleLineCommentsInSelection()
|
||||
|
||||
expect(buffer.lineForRow(4)).toBe "// while(items.length > 0) {"
|
||||
expect(buffer.lineForRow(5)).toBe " current = items.shift();"
|
||||
expect(buffer.lineForRow(6)).toBe "// current < pivot ? left.push(current) : right.push(current);"
|
||||
expect(buffer.lineForRow(7)).toBe " }"
|
||||
|
||||
editSession.setSelectedBufferRange([[4, 5], [7, 5]])
|
||||
editSession.toggleLineCommentsInSelection()
|
||||
|
||||
expect(buffer.lineForRow(4)).toBe " while(items.length > 0) {"
|
||||
expect(buffer.lineForRow(5)).toBe " current = items.shift();"
|
||||
expect(buffer.lineForRow(6)).toBe " current < pivot ? left.push(current) : right.push(current);"
|
||||
expect(buffer.lineForRow(7)).toBe " }"
|
||||
|
||||
it "preserves selection emptiness", ->
|
||||
editSession.setSelectedBufferRange([[4, 0], [4, 0]])
|
||||
editSession.toggleLineCommentsInSelection()
|
||||
|
||||
@@ -55,8 +55,8 @@ class LanguageMode
|
||||
for row in [range.start.row..range.end.row]
|
||||
line = @editSession.lineForBufferRow(row)
|
||||
if shouldUncomment
|
||||
match = commentRegex.search(line)
|
||||
@editSession.buffer.change([[row, 0], [row, match[0].length]], "")
|
||||
if match = commentRegex.search(line)
|
||||
@editSession.buffer.change([[row, 0], [row, match[0].length]], "")
|
||||
else
|
||||
@editSession.buffer.insert([row, 0], commentString)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user