mirror of
https://github.com/atom/atom.git
synced 2026-01-25 06:48:28 -05:00
Move undo/redo specs to edit-session-spec
This commit is contained in:
@@ -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]
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user