From 8a34ea20c470a04fa3fa61129b961f3d3f3f8175 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Tue, 12 Jun 2012 13:44:40 -0600 Subject: [PATCH] Move undo/redo specs to edit-session-spec --- spec/app/edit-session-spec.coffee | 51 ++++++++++++++++++++++++ spec/app/editor-spec.coffee | 65 ------------------------------- 2 files changed, 51 insertions(+), 65 deletions(-) diff --git a/spec/app/edit-session-spec.coffee b/spec/app/edit-session-spec.coffee index 3560df36e..ca06e249d 100644 --- a/spec/app/edit-session-spec.coffee +++ b/spec/app/edit-session-spec.coffee @@ -946,6 +946,57 @@ describe "EditSession", -> expect(editSession.buffer.lineForRow(0)).toBe "var first = function () {" expect(buffer.lineForRow(1)).toBe " var first = function(items) {" + describe ".undo() and .redo()", -> + it "undoes/redoes the last change", -> + editSession.insertText("foo") + editSession.undo() + expect(buffer.lineForRow(0)).not.toContain "foo" + + editSession.redo() + expect(buffer.lineForRow(0)).toContain "foo" + + it "batches the undo / redo of changes caused by multiple cursors", -> + editSession.setCursorScreenPosition([0, 0]) + editSession.addCursorAtScreenPosition([1, 0]) + + editSession.insertText("foo") + editSession.backspace() + + expect(buffer.lineForRow(0)).toContain "fovar" + expect(buffer.lineForRow(1)).toContain "fo " + + editSession.undo() + + expect(buffer.lineForRow(0)).toContain "foo" + expect(buffer.lineForRow(1)).toContain "foo" + + editSession.redo() + + expect(buffer.lineForRow(0)).not.toContain "foo" + expect(buffer.lineForRow(0)).toContain "fovar" + + it "restores the selected ranges after undo and redo", -> + editSession.setSelectedBufferRanges([[[1, 6], [1, 10]], [[1, 22], [1, 27]]]) + editSession.delete() + editSession.delete() + + selections = editSession.getSelections() + expect(buffer.lineForRow(1)).toBe ' var = function( {' + expect(selections[0].getBufferRange()).toEqual [[1, 6], [1, 6]] + expect(selections[1].getBufferRange()).toEqual [[1, 17], [1, 17]] + + editSession.undo() + expect(selections[0].getBufferRange()).toEqual [[1, 6], [1, 6]] + expect(selections[1].getBufferRange()).toEqual [[1, 18], [1, 18]] + + editSession.undo() + expect(selections[0].getBufferRange()).toEqual [[1, 6], [1, 10]] + expect(selections[1].getBufferRange()).toEqual [[1, 22], [1, 27]] + + editSession.redo() + expect(selections[0].getBufferRange()).toEqual [[1, 6], [1, 6]] + expect(selections[1].getBufferRange()).toEqual [[1, 18], [1, 18]] + describe "when the buffer is changed (via its direct api, rather than via than edit session)", -> it "moves the cursor so it is in the same relative position of the buffer", -> expect(editSession.getCursorScreenPosition()).toEqual [0, 0] diff --git a/spec/app/editor-spec.coffee b/spec/app/editor-spec.coffee index d006f7d47..8559a77e7 100644 --- a/spec/app/editor-spec.coffee +++ b/spec/app/editor-spec.coffee @@ -1357,71 +1357,6 @@ describe "Editor", -> expect(editor.getCursorScreenPosition()).toEqual(row: 1, column: 7) expect(editor.renderedLines.find('.line:eq(1)')).toHaveText buffer.lineForRow(1) - describe "undo/redo", -> - it "undoes/redoes the last change", -> - buffer.insert [0, 0], "foo" - editor.trigger 'undo' - expect(buffer.lineForRow(0)).not.toContain "foo" - - editor.trigger 'redo' - expect(buffer.lineForRow(0)).toContain "foo" - - it "batches the undo / redo of changes caused by multiple cursors", -> - editor.setCursorScreenPosition([0, 0]) - editor.addCursorAtScreenPosition([1, 0]) - - editor.insertText("foo") - editor.backspace() - - expect(buffer.lineForRow(0)).toContain "fovar" - expect(buffer.lineForRow(1)).toContain "fo " - - editor.trigger 'undo' - - expect(buffer.lineForRow(0)).toContain "foo" - expect(buffer.lineForRow(1)).toContain "foo" - - editor.trigger 'undo' - - expect(buffer.lineForRow(0)).not.toContain "foo" - expect(buffer.lineForRow(1)).not.toContain "foo" - - it "restores the selected ranges after undo", -> - editor.setSelectedBufferRanges([[[1, 6], [1, 10]], [[1, 22], [1, 27]]]) - editor.delete() - editor.delete() - - selections = editor.getSelections() - expect(buffer.lineForRow(1)).toBe ' var = function( {' - expect(selections[0].getBufferRange()).toEqual [[1, 6], [1, 6]] - expect(selections[1].getBufferRange()).toEqual [[1, 17], [1, 17]] - - editor.trigger 'undo' - expect(selections[0].getBufferRange()).toEqual [[1, 6], [1, 6]] - expect(selections[1].getBufferRange()).toEqual [[1, 18], [1, 18]] - - editor.trigger 'undo' - expect(selections[0].getBufferRange()).toEqual [[1, 6], [1, 10]] - expect(selections[1].getBufferRange()).toEqual [[1, 22], [1, 27]] - - editor.trigger 'redo' - expect(selections[0].getBufferRange()).toEqual [[1, 6], [1, 6]] - expect(selections[1].getBufferRange()).toEqual [[1, 18], [1, 18]] - - it "restores the selected ranges after redo", -> - editor.setSelectedBufferRanges([[[1, 6], [1, 10]], [[1, 22], [1, 27]]]) - selections = editor.getSelections() - - editor.insertText("booboo") - expect(selections[0].getBufferRange()).toEqual [[1, 12], [1, 12]] - expect(selections[1].getBufferRange()).toEqual [[1, 30], [1, 30]] - - editor.undo() - editor.redo() - - expect(selections[0].getBufferRange()).toEqual [[1, 12], [1, 12]] - expect(selections[1].getBufferRange()).toEqual [[1, 30], [1, 30]] - describe "when the editor is attached to the dom", -> it "calculates line height and char width and updates the pixel position of the cursor", -> expect(editor.lineHeight).toBeNull()