diff --git a/spec/app/editor-spec.coffee b/spec/app/editor-spec.coffee index d7eeb99a8..a39edcb7f 100644 --- a/spec/app/editor-spec.coffee +++ b/spec/app/editor-spec.coffee @@ -26,6 +26,20 @@ describe "Editor", -> editor.insertText('x') expect(editor.lines.find('.line').length).toBe 1 + describe ".copy()", -> + it "builds a new editor with the same edit sessions, cursor position, and scroll position as the receiver", -> + editor.setCursorScreenPosition([1, 1]) + + # prove this test covers serialization and deserialization + spyOn(editor, 'serialize').andCallThrough() + spyOn(Editor, 'deserialize').andCallThrough() + + newEditor = editor.copy() + expect(editor.serialize).toHaveBeenCalled() + expect(Editor.deserialize).toHaveBeenCalled() + expect(newEditor.buffer).toBe editor.buffer + expect(newEditor.getCursorScreenPosition()).toEqual editor.getCursorScreenPosition() + describe "text rendering", -> it "creates a line element for each line in the buffer with the html-escaped text of the line", -> expect(editor.lines.find('.line').length).toEqual(buffer.numLines()) diff --git a/src/app/editor.coffee b/src/app/editor.coffee index a553f9dc0..f0228a3e2 100644 --- a/src/app/editor.coffee +++ b/src/app/editor.coffee @@ -67,7 +67,7 @@ class Editor extends View { viewClass: "Editor", @editSessions, @activeEditSessionIndex, @isFocused } copy: -> - new Editor(@serialize()) + Editor.deserialize(@serialize()) bindKeys: -> @on 'save', => @save()