diff --git a/spec/app/edit-session-spec.coffee b/spec/app/edit-session-spec.coffee index 1fca7a06f..03eb55893 100644 --- a/spec/app/edit-session-spec.coffee +++ b/spec/app/edit-session-spec.coffee @@ -880,6 +880,7 @@ describe "EditSession", -> editSession.delete() expect(buffer.lineForRow(1)).toBe ' var sort = function(it) {' expect(buffer.lineForRow(2)).toBe 'if (items.length <= 1) return items;' + expect(editSession.getSelection().isEmpty()).toBeTruthy() describe "when there are multiple selections", -> describe "when selections are on the same line", -> @@ -1043,6 +1044,28 @@ describe "EditSession", -> expect(buffer.lineForRow(2)).toBe " if (items.length <= 1) return items;" expect(editSession.getSelectedBufferRange()).toEqual [[0, 1], [3, 15 - tabLength]] + describe ".toggleLineCommentsInSelection()", -> + it "toggles comments on the selected lines", -> + 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 "// }" + expect(editSession.getSelectedBufferRange()).toEqual [[4, 7], [7, 7]] + + 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() + expect(editSession.getSelection().isEmpty()).toBeTruthy() + describe ".undo() and .redo()", -> it "undoes/redoes the last change", -> editSession.insertText("foo") diff --git a/spec/app/selection-spec.coffee b/spec/app/selection-spec.coffee index 6489529c3..126b010e3 100644 --- a/spec/app/selection-spec.coffee +++ b/spec/app/selection-spec.coffee @@ -171,31 +171,6 @@ describe "Selection", -> selection.selectToScreenPosition([0, 25]) expect(selection.isReversed()).toBeFalsy() - describe ".toggleLineComments()", -> - it "toggles comments on the selected lines", -> - selection.setBufferRange([[4, 5], [7, 5]]) - selection.toggleLineComments() - - 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 "// }" - - expect(selection.getBufferRange()).toEqual [[4, 7], [7, 7]] - - selection.toggleLineComments() - 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", -> - editor.attachToDom() - selection.setBufferRange([[4, 0], [4, 0]]) - selection.toggleLineComments() - expect(selection.isEmpty()).toBeTruthy() - expect(selectionView.find('.selection')).not.toExist() - describe "when the selection ends on the begining of a fold line", -> beforeEach -> editor.createFold(2,4) diff --git a/src/app/edit-session.coffee b/src/app/edit-session.coffee index c32ecaaf3..e836ce524 100644 --- a/src/app/edit-session.coffee +++ b/src/app/edit-session.coffee @@ -144,7 +144,7 @@ class EditSession outdentSelectedRows: -> @mutateSelectedText (selection) -> selection.outdentSelectedRows() - toggleCommentsInSelection: -> + toggleLineCommentsInSelection: -> @mutateSelectedText (selection) -> selection.toggleLineComments() cutToEndOfLine: ->