From fa6ea01bfc00fb1ebf4717166ea118a0632aedde Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Wed, 14 Aug 2013 10:49:48 -0600 Subject: [PATCH] Restore assignment of @project ivar in TextBuffer Because TextBuffers need a reference to `project` during deserialization, and because the project global deserializes text buffers while it itself is being deserialized (which happens before the global is actually assigned), we have to pass a project reference into TextBuffer. This is really annoying and makes me want to store the references to open buffers elsewhere. But for now it's the only way to break the circularity. --- src/app/text-buffer.coffee | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/app/text-buffer.coffee b/src/app/text-buffer.coffee index acfe07d0f..6affbf826 100644 --- a/src/app/text-buffer.coffee +++ b/src/app/text-buffer.coffee @@ -33,12 +33,13 @@ class TextBuffer # initialText - A {String} setting the starting text constructor: (optionsOrState={}, params={}) -> if optionsOrState instanceof telepath.Document + {@project} = params @state = optionsOrState @text = @state.get('text') filePath = @state.get('relativePath') @id = @state.get('id') else - {filePath, initialText} = optionsOrState + {@project, filePath, initialText} = optionsOrState @text = site.createDocument(initialText, shareStrings: true) if initialText @id = guid.create().toString() @state = site.createDocument @@ -47,7 +48,7 @@ class TextBuffer version: @constructor.version if filePath - @setPath(project.resolve(filePath)) + @setPath(@project.resolve(filePath)) if @text @updateCachedDiskContents() else @@ -74,7 +75,7 @@ class TextBuffer unless @destroyed @file?.off() @destroyed = true - project?.removeBuffer(this) + @project?.removeBuffer(this) retain: -> @refcount++ @@ -156,7 +157,7 @@ class TextBuffer @state.get('relativePath') setRelativePath: (relativePath) -> - @setPath(project.resolve(relativePath)) + @setPath(@project.resolve(relativePath)) # Sets the path for the file. # @@ -168,7 +169,7 @@ class TextBuffer @file = new File(path) @file.read() if @file.exists() @subscribeToFile() - @state.set('relativePath', project.relativize(path)) + @state.set('relativePath', @project.relativize(path)) @trigger "path-changed", this # Retrieves the current buffer's file extension. @@ -593,7 +594,7 @@ class TextBuffer checkoutHead: -> path = @getPath() return unless path - project.getRepo()?.checkoutHead(path) + @project.getRepo()?.checkoutHead(path) # Checks to see if a file exists. #