Ensure that Editor.proto.serialize returns a copy of each edit session

This commit is contained in:
Nathan Sobo
2012-04-13 14:29:58 -06:00
parent 65c624f2bf
commit c673c5114e
2 changed files with 9 additions and 2 deletions

View File

@@ -40,6 +40,9 @@ describe "Editor", ->
expect(newEditor.buffer).toBe editor.buffer
expect(newEditor.getCursorScreenPosition()).toEqual editor.getCursorScreenPosition()
expect(newEditor.editSessions[0]).toEqual(editor.editSessions[0])
expect(newEditor.editSessions[0]).not.toBe(editor.editSessions[0])
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())

View File

@@ -38,6 +38,7 @@ class Editor extends View
isFocused: false
softTabs: true
tabText: ' '
editSessions: null
@deserialize: (viewState) ->
new Editor(viewState)
@@ -64,7 +65,10 @@ class Editor extends View
serialize: ->
@saveCurrentEditSession()
{ viewClass: "Editor", @editSessions, @activeEditSessionIndex, @isFocused }
{ viewClass: "Editor", editSessions: @serializeEditSessions(), @activeEditSessionIndex, @isFocused }
serializeEditSessions: ->
@editSessions.map (session) -> _.clone(session)
copy: ->
Editor.deserialize(@serialize())
@@ -512,7 +516,7 @@ class Editor extends View
return super if keepData
@unsubscribeFromBuffer()
rootView = @rootView()
if @pane() then @pane.remove() else super
if @pane() then @pane().remove() else super
rootView?.focus()
unsubscribeFromBuffer: ->