From b841a0409399b5dc951e5415a4e79d8f86a97b08 Mon Sep 17 00:00:00 2001 From: Corey Johnson Date: Tue, 12 Jun 2012 15:12:46 -0700 Subject: [PATCH] Don't serialize pathless buffer text --- spec/app/buffer-spec.coffee | 4 ++-- src/app/buffer.coffee | 16 +++------------- 2 files changed, 5 insertions(+), 15 deletions(-) diff --git a/spec/app/buffer-spec.coffee b/spec/app/buffer-spec.coffee index f1478a3bb..676c90218 100644 --- a/spec/app/buffer-spec.coffee +++ b/spec/app/buffer-spec.coffee @@ -81,11 +81,11 @@ describe 'Buffer', -> expect(buffer).toBe savedBuffer describe 'when the state has text (and no path)', -> - it 'creates a new buffer with the given text', -> + it 'creates a new empty buffer (does not serialze unsaved text)', -> unsavedBuffer = project.open() unsavedBuffer.setText("OMGWTFBBQ") buffer = Buffer.deserialize(unsavedBuffer.serialize(), project) - expect(buffer).toBe unsavedBuffer + expect(buffer.getText()).toBe "" describe ".getLines()", -> it "returns an array of lines in the text contents", -> diff --git a/src/app/buffer.coffee b/src/app/buffer.coffee index 525b9a5eb..79110dbcb 100644 --- a/src/app/buffer.coffee +++ b/src/app/buffer.coffee @@ -13,20 +13,13 @@ class Buffer path: null @deserialize: (state, project) -> - if state.path - buffer = project.open(state.path) - else - buffer = project.bufferWithId(state.id) ? project.open() - buffer.setText(state.text) - buffer.modified = state.modified - - buffer + project.open(state.path) constructor: (path) -> @id = @constructor.idCounter++ @setPath(path) @lines = [''] - if @getPath() and fs.exists(@getPath()) + if fs.exists(@getPath()) @setText(fs.read(@getPath())) else @setText('') @@ -34,10 +27,7 @@ class Buffer @modified = false serialize: -> - if @getPath() - { path: @path } - else - { text: @getText(), id: @id , modified: @modified} + path: @getPath() getPath: -> @path