diff --git a/spec/app/edit-session-spec.coffee b/spec/app/edit-session-spec.coffee index c77355740..9eb71c9d5 100644 --- a/spec/app/edit-session-spec.coffee +++ b/spec/app/edit-session-spec.coffee @@ -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() diff --git a/src/app/language-mode.coffee b/src/app/language-mode.coffee index 9e52d49d4..2f519c8f7 100644 --- a/src/app/language-mode.coffee +++ b/src/app/language-mode.coffee @@ -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)