From 63e3be8630dba57efe7e75fc0956af5fe96eabd7 Mon Sep 17 00:00:00 2001 From: probablycorey Date: Mon, 9 Dec 2013 11:06:29 -0800 Subject: [PATCH 01/37] Only mark a deleted file as modified if it was previously modified. Fixes #693 --- spec/text-buffer-spec.coffee | 55 ++++++++++++++++++++---------------- src/text-buffer.coffee | 6 ++-- 2 files changed, 33 insertions(+), 28 deletions(-) diff --git a/spec/text-buffer-spec.coffee b/spec/text-buffer-spec.coffee index 31066cd5b..de468183a 100644 --- a/spec/text-buffer-spec.coffee +++ b/spec/text-buffer-spec.coffee @@ -34,11 +34,11 @@ describe 'TextBuffer', -> expect(buffer.getText()).toBe fs.readFileSync(filePath, 'utf8') describe "when no file exists for the path", -> - it "is modified and is initially empty", -> + it "is not modified and is initially empty", -> filePath = "does-not-exist.txt" expect(fs.existsSync(filePath)).toBeFalsy() buffer = atom.project.bufferForPathSync(filePath) - expect(buffer.isModified()).toBeTruthy() + expect(buffer.isModified()).not.toBeTruthy() expect(buffer.getText()).toBe '' describe "when no path is given", -> @@ -160,20 +160,38 @@ describe 'TextBuffer', -> filePath = bufferToDelete.getPath() # symlinks may have been converted expect(bufferToDelete.getPath()).toBe filePath - expect(bufferToDelete.isModified()).toBeFalsy() - - removeHandler = jasmine.createSpy('removeHandler') - bufferToDelete.file.on 'removed', removeHandler - fs.removeSync(filePath) - waitsFor "file to be removed", -> - removeHandler.callCount > 0 afterEach -> bufferToDelete.destroy() - it "retains its path and reports the buffer as modified", -> - expect(bufferToDelete.getPath()).toBe filePath - expect(bufferToDelete.isModified()).toBeTruthy() + describe "when the file is modified", -> + beforeEach -> + bufferToDelete.setText("I WAS MODIFIED") + expect(bufferToDelete.isModified()).toBeTruthy() + + removeHandler = jasmine.createSpy('removeHandler') + bufferToDelete.file.on 'removed', removeHandler + fs.removeSync(filePath) + waitsFor "file to be removed", -> + removeHandler.callCount > 0 + + it "retains its path and reports the buffer as modified", -> + expect(bufferToDelete.getPath()).toBe filePath + expect(bufferToDelete.isModified()).toBeTruthy() + + describe "when the file is not modified", -> + beforeEach -> + expect(bufferToDelete.isModified()).toBeFalsy() + + removeHandler = jasmine.createSpy('removeHandler') + bufferToDelete.file.on 'removed', removeHandler + fs.removeSync(filePath) + waitsFor "file to be removed", -> + removeHandler.callCount > 0 + + it "retains its path and reports the buffer as not modified", -> + expect(bufferToDelete.getPath()).toBe filePath + expect(bufferToDelete.isModified()).toBeFalsy() it "resumes watching of the file when it is re-saved", -> bufferToDelete.save() @@ -210,19 +228,6 @@ describe 'TextBuffer', -> advanceClock(buffer.stoppedChangingDelay) expect(modifiedHandler).toHaveBeenCalledWith(false) - it "reports the modified status changing to true after the underlying file is deleted", -> - buffer.release() - filePath = path.join(temp.dir, 'atom-tmp-file') - fs.writeFileSync(filePath, 'delete me') - buffer = atom.project.bufferForPathSync(filePath) - modifiedHandler = jasmine.createSpy("modifiedHandler") - buffer.on 'modified-status-changed', modifiedHandler - - fs.removeSync(filePath) - - waitsFor "modified status to change", -> modifiedHandler.callCount - runs -> expect(buffer.isModified()).toBe true - it "reports the modified status changing to false after a modified buffer is saved", -> filePath = path.join(temp.dir, 'atom-tmp-file') fs.writeFileSync(filePath, '') diff --git a/src/text-buffer.coffee b/src/text-buffer.coffee index a32913679..ed1a7f086 100644 --- a/src/text-buffer.coffee +++ b/src/text-buffer.coffee @@ -117,8 +117,8 @@ class TextBuffer extends telepath.Model @reload() @file.on "removed", => - @updateCachedDiskContents().done => - @emitModifiedStatusChanged(@isModified()) + @wasModifiedBeforeRemove = @getText() != @cachedDiskContents + @updateCachedDiskContents() @file.on "moved", => @emit "path-changed", this @@ -403,7 +403,7 @@ class TextBuffer extends telepath.Model if @file.exists() @getText() != @cachedDiskContents else - true + @wasModifiedBeforeRemove ? not @isEmpty() else not @isEmpty() From ec3e13963212cf9a22c6f40507807f19cfec86b2 Mon Sep 17 00:00:00 2001 From: probablycorey Date: Mon, 9 Dec 2013 11:41:57 -0800 Subject: [PATCH 02/37] Project doesn't serialize non-modified buffers that don't exist on disk --- spec/project-spec.coffee | 12 ++++++++++++ src/project.coffee | 4 ++++ 2 files changed, 16 insertions(+) diff --git a/spec/project-spec.coffee b/spec/project-spec.coffee index adc6e15d0..e8e292574 100644 --- a/spec/project-spec.coffee +++ b/spec/project-spec.coffee @@ -26,6 +26,18 @@ describe "Project", -> expect(deserializedProject.getBuffers().length).toBe 0 expect(atom.project.getBuffers().length).toBe 0 + it "destroys non-existent non-modified buffers and does not include them in the serialized state", -> + nonExistentNonModified = atom.project.openSync("non-existent-non-modified.txt") + nonExistentModified = atom.project.openSync("non-existent-modified.txt") + nonExistentModified.setText("I am modified") + expect(atom.project.getBuffers().length).toBe 2 + + atom.project.getState().serializeForPersistence() + deserializedProject = atom.replicate().get('project') + + expect(deserializedProject.getBuffers().length).toBe 1 + expect(atom.project.getBuffers().length).toBe 1 + it "listens for destroyed events on deserialized buffers and removes them when they are destroyed", -> atom.project.openSync('a') expect(atom.project.getBuffers().length).toBe 1 diff --git a/src/project.coffee b/src/project.coffee index 8b1758e28..bf8f7bb7f 100644 --- a/src/project.coffee +++ b/src/project.coffee @@ -43,6 +43,7 @@ class Project extends telepath.Model # Private: Called by telepath. beforePersistence: -> @destroyUnretainedBuffers() + @destroyNonExistentNonModified() # Public: Register an opener for project files. # @@ -77,6 +78,9 @@ class Project extends telepath.Model destroyUnretainedBuffers: -> buffer.destroy() for buffer in @getBuffers() when not buffer.isRetained() + destroyNonExistentNonModified: -> + buffer.destroy() for buffer in @getBuffers() when not buffer.isModified() and not buffer.file.exists() + # Public: Returns the {Git} repository if available. getRepo: -> @repo From 22ec8c3a75c3ddfd7b5b29a21fefd58819f26419 Mon Sep 17 00:00:00 2001 From: probablycorey Date: Mon, 9 Dec 2013 12:06:44 -0800 Subject: [PATCH 03/37] Rename destroyNonExistentNonModified --- src/project.coffee | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/project.coffee b/src/project.coffee index bf8f7bb7f..8c6cd956c 100644 --- a/src/project.coffee +++ b/src/project.coffee @@ -43,7 +43,7 @@ class Project extends telepath.Model # Private: Called by telepath. beforePersistence: -> @destroyUnretainedBuffers() - @destroyNonExistentNonModified() + @destroyUnmodifiedNonExistentBuffers() # Public: Register an opener for project files. # @@ -78,7 +78,7 @@ class Project extends telepath.Model destroyUnretainedBuffers: -> buffer.destroy() for buffer in @getBuffers() when not buffer.isRetained() - destroyNonExistentNonModified: -> + destroyUnmodifiedNonExistentBuffers: -> buffer.destroy() for buffer in @getBuffers() when not buffer.isModified() and not buffer.file.exists() # Public: Returns the {Git} repository if available. From 51ff3ec46acacf8dd955ac53a9448348cb7c1edc Mon Sep 17 00:00:00 2001 From: probablycorey Date: Tue, 10 Dec 2013 10:14:56 -0800 Subject: [PATCH 04/37] Revert "Rename destroyNonExistentNonModified" This reverts commit 22ec8c3a75c3ddfd7b5b29a21fefd58819f26419. --- src/project.coffee | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/project.coffee b/src/project.coffee index 8c6cd956c..bf8f7bb7f 100644 --- a/src/project.coffee +++ b/src/project.coffee @@ -43,7 +43,7 @@ class Project extends telepath.Model # Private: Called by telepath. beforePersistence: -> @destroyUnretainedBuffers() - @destroyUnmodifiedNonExistentBuffers() + @destroyNonExistentNonModified() # Public: Register an opener for project files. # @@ -78,7 +78,7 @@ class Project extends telepath.Model destroyUnretainedBuffers: -> buffer.destroy() for buffer in @getBuffers() when not buffer.isRetained() - destroyUnmodifiedNonExistentBuffers: -> + destroyNonExistentNonModified: -> buffer.destroy() for buffer in @getBuffers() when not buffer.isModified() and not buffer.file.exists() # Public: Returns the {Git} repository if available. From 19da22d440433f3ec431182c4a65a40a77f519f0 Mon Sep 17 00:00:00 2001 From: probablycorey Date: Tue, 10 Dec 2013 10:15:03 -0800 Subject: [PATCH 05/37] Revert "Project doesn't serialize non-modified buffers that don't exist on disk" This reverts commit ec3e13963212cf9a22c6f40507807f19cfec86b2. --- spec/project-spec.coffee | 12 ------------ src/project.coffee | 4 ---- 2 files changed, 16 deletions(-) diff --git a/spec/project-spec.coffee b/spec/project-spec.coffee index e8e292574..adc6e15d0 100644 --- a/spec/project-spec.coffee +++ b/spec/project-spec.coffee @@ -26,18 +26,6 @@ describe "Project", -> expect(deserializedProject.getBuffers().length).toBe 0 expect(atom.project.getBuffers().length).toBe 0 - it "destroys non-existent non-modified buffers and does not include them in the serialized state", -> - nonExistentNonModified = atom.project.openSync("non-existent-non-modified.txt") - nonExistentModified = atom.project.openSync("non-existent-modified.txt") - nonExistentModified.setText("I am modified") - expect(atom.project.getBuffers().length).toBe 2 - - atom.project.getState().serializeForPersistence() - deserializedProject = atom.replicate().get('project') - - expect(deserializedProject.getBuffers().length).toBe 1 - expect(atom.project.getBuffers().length).toBe 1 - it "listens for destroyed events on deserialized buffers and removes them when they are destroyed", -> atom.project.openSync('a') expect(atom.project.getBuffers().length).toBe 1 diff --git a/src/project.coffee b/src/project.coffee index bf8f7bb7f..8b1758e28 100644 --- a/src/project.coffee +++ b/src/project.coffee @@ -43,7 +43,6 @@ class Project extends telepath.Model # Private: Called by telepath. beforePersistence: -> @destroyUnretainedBuffers() - @destroyNonExistentNonModified() # Public: Register an opener for project files. # @@ -78,9 +77,6 @@ class Project extends telepath.Model destroyUnretainedBuffers: -> buffer.destroy() for buffer in @getBuffers() when not buffer.isRetained() - destroyNonExistentNonModified: -> - buffer.destroy() for buffer in @getBuffers() when not buffer.isModified() and not buffer.file.exists() - # Public: Returns the {Git} repository if available. getRepo: -> @repo From 8ffa8fed12999353c45ff21ba75ca4d361867a50 Mon Sep 17 00:00:00 2001 From: probablycorey Date: Tue, 10 Dec 2013 13:50:51 -0800 Subject: [PATCH 06/37] Always use Pane::addItem when adding items. --- src/pane.coffee | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/pane.coffee b/src/pane.coffee index 57827b803..6c10472be 100644 --- a/src/pane.coffee +++ b/src/pane.coffee @@ -31,15 +31,18 @@ class Pane extends View # Private: initialize: (args...) -> + @items = [] if args[0] instanceof telepath.Document @state = args[0] - @items = _.compact @state.get('items').map (item) -> - atom.deserializers.deserialize(item) + _.compact @state.get('items').each (item) => + @addItem(item, @items.length) if item = atom.deserializers.deserialize(item) + else - @items = args + items = args @state = atom.site.createDocument deserializer: 'Pane' - items: @items.map (item) -> item.getState?() ? item.serialize() + items: items.map (item) -> item.getState?() ? item.serialize() + items.forEach (item) => @addItem(item, @items.length) @subscribe @state.get('items'), 'changed', ({index, removedValues, insertedValues, siteId}) => return if siteId is @state.siteId From a3eb76d630ee4e8554eeecad7d2829b4fb36c6be Mon Sep 17 00:00:00 2001 From: probablycorey Date: Tue, 10 Dec 2013 13:52:42 -0800 Subject: [PATCH 07/37] :lipstick: --- src/pane.coffee | 1 - 1 file changed, 1 deletion(-) diff --git a/src/pane.coffee b/src/pane.coffee index 6c10472be..765e914dc 100644 --- a/src/pane.coffee +++ b/src/pane.coffee @@ -36,7 +36,6 @@ class Pane extends View @state = args[0] _.compact @state.get('items').each (item) => @addItem(item, @items.length) if item = atom.deserializers.deserialize(item) - else items = args @state = atom.site.createDocument From 201717a9aa7254c4448cc3c72318c20fcaf8e2a3 Mon Sep 17 00:00:00 2001 From: probablycorey Date: Tue, 10 Dec 2013 17:04:46 -0800 Subject: [PATCH 08/37] Remove duplicate destroy Telepath now emits the 'destroy' event --- src/text-buffer.coffee | 1 - 1 file changed, 1 deletion(-) diff --git a/src/text-buffer.coffee b/src/text-buffer.coffee index 68c4fabab..91125a888 100644 --- a/src/text-buffer.coffee +++ b/src/text-buffer.coffee @@ -87,7 +87,6 @@ class TextBuffer extends telepath.Model @file?.off() @unsubscribe() @alreadyDestroyed = true - @emit 'destroyed', this isRetained: -> @refcount > 0 From 4bfcdf4d5b456e54bb214c643425916423cf9b65 Mon Sep 17 00:00:00 2001 From: probablycorey Date: Tue, 10 Dec 2013 17:08:07 -0800 Subject: [PATCH 09/37] Remove unmodified editors from pane when the buffer is deleted --- spec/pane-spec.coffee | 21 ++++++++++++++++----- src/editor.coffee | 1 + src/pane.coffee | 6 ++++-- src/text-buffer.coffee | 8 ++++++-- 4 files changed, 27 insertions(+), 9 deletions(-) diff --git a/spec/pane-spec.coffee b/spec/pane-spec.coffee index 75d3661dc..3c367eac5 100644 --- a/spec/pane-spec.coffee +++ b/spec/pane-spec.coffee @@ -1,6 +1,6 @@ PaneContainer = require '../src/pane-container' Pane = require '../src/pane' -{$, View} = require 'atom' +{fs, $, View} = require 'atom' path = require 'path' temp = require 'temp' @@ -347,14 +347,14 @@ describe "Pane", -> describe "when the current item has a saveAs method", -> it "opens a save dialog and saves the current item as the selected path", -> - spyOn(editor2, 'saveAs') - editor2.buffer.setPath(undefined) - pane.showItem(editor2) + newEditor = atom.project.openSync() + spyOn(newEditor, 'saveAs') + pane.showItem(newEditor) pane.trigger 'core:save' expect(atom.showSaveDialogSync).toHaveBeenCalled() - expect(editor2.saveAs).toHaveBeenCalledWith('/selected/path') + expect(newEditor.saveAs).toHaveBeenCalledWith('/selected/path') describe "when the current item has no saveAs method", -> it "does nothing", -> @@ -421,6 +421,17 @@ describe "Pane", -> view2.trigger 'title-changed' expect(activeItemTitleChangedHandler).toHaveBeenCalled() + describe "when an unmodifed buffer's path is deleted its pane item is removed", -> + it "removes the pane item", -> + filePath = temp.openSync('atom').path + editor = atom.project.openSync(filePath) + pane.showItem(editor) + expect(pane.items).toHaveLength(5) + + fs.removeSync(filePath) + waitsFor -> + pane.items.length == 4 + describe ".remove()", -> it "destroys all the pane's items", -> pane.remove() diff --git a/src/editor.coffee b/src/editor.coffee index 51cf56c98..f8fdef4d8 100644 --- a/src/editor.coffee +++ b/src/editor.coffee @@ -121,6 +121,7 @@ class Editor @subscribe @buffer, "contents-modified", => @emit "contents-modified" @subscribe @buffer, "contents-conflicted", => @emit "contents-conflicted" @subscribe @buffer, "modified-status-changed", => @emit "modified-status-changed" + @subscribe @buffer, "destroyed", => @destroy() @preserveCursorPositionOnBufferReload() # Private: diff --git a/src/pane.coffee b/src/pane.coffee index 765e914dc..112ee045d 100644 --- a/src/pane.coffee +++ b/src/pane.coffee @@ -189,6 +189,8 @@ class Pane extends View @items.splice(index, 0, item) @getContainer()?.itemAdded(item) @trigger 'pane:item-added', [item, index] + if item.on + @subscribe item, 'destroyed', => @destroyItem(item) item # Public: Remove the currently active item. @@ -198,11 +200,11 @@ class Pane extends View # Public: Remove the specified item. destroyItem: (item) -> + @unsubscribe(item) if item.off @trigger 'pane:before-item-destroyed', [item] - container = @getContainer() if @promptToSaveItem(item) - container.itemDestroyed(item) + @getContainer()?.itemDestroyed(item) @removeItem(item) item.destroy?() true diff --git a/src/text-buffer.coffee b/src/text-buffer.coffee index 91125a888..a63406c99 100644 --- a/src/text-buffer.coffee +++ b/src/text-buffer.coffee @@ -116,8 +116,12 @@ class TextBuffer extends telepath.Model @reload() @file.on "removed", => - @wasModifiedBeforeRemove = @getText() != @cachedDiskContents - @updateCachedDiskContents() + modified = @getText() != @cachedDiskContents + @wasModifiedBeforeRemove = modified + if modified + @updateCachedDiskContents() + else + @destroy() @file.on "moved", => @emit "path-changed", this From 115203cbd285c3a676e2850cb6759ff108e3640a Mon Sep 17 00:00:00 2001 From: probablycorey Date: Wed, 11 Dec 2013 14:48:12 -0800 Subject: [PATCH 10/37] Update spec description --- spec/pane-spec.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/pane-spec.coffee b/spec/pane-spec.coffee index 3c367eac5..e82ef9f97 100644 --- a/spec/pane-spec.coffee +++ b/spec/pane-spec.coffee @@ -421,7 +421,7 @@ describe "Pane", -> view2.trigger 'title-changed' expect(activeItemTitleChangedHandler).toHaveBeenCalled() - describe "when an unmodifed buffer's path is deleted its pane item is removed", -> + describe "when an unmodifed buffer's path is deleted", -> it "removes the pane item", -> filePath = temp.openSync('atom').path editor = atom.project.openSync(filePath) From e0ad22d0bd6661c17df10b58d5925f7b21fede55 Mon Sep 17 00:00:00 2001 From: probablycorey Date: Wed, 11 Dec 2013 14:51:44 -0800 Subject: [PATCH 11/37] Don't pop-up save dialog in specs --- spec/editor-view-spec.coffee | 3 +++ spec/workspace-view-spec.coffee | 2 ++ 2 files changed, 5 insertions(+) diff --git a/spec/editor-view-spec.coffee b/spec/editor-view-spec.coffee index bd4f71dcf..f1ec0d19c 100644 --- a/spec/editor-view-spec.coffee +++ b/spec/editor-view-spec.coffee @@ -1,5 +1,6 @@ WorkspaceView = require '../src/workspace-view' EditorView = require '../src/editor-view' +Pane = require '../src/pane' {$, $$} = require '../src/space-pen-extensions' _ = require 'underscore-plus' fs = require 'fs-plus' @@ -2750,6 +2751,8 @@ describe "EditorView", -> describe "when the editor view is attached but invisible", -> describe "when the editor view's text is changed", -> it "redraws the editor view when it is next shown", -> + spyOn(Pane.prototype, "promptToSaveItem").andReturn false + atom.workspaceView = new WorkspaceView atom.workspaceView.openSync('sample.js') atom.workspaceView.attachToDom() diff --git a/spec/workspace-view-spec.coffee b/spec/workspace-view-spec.coffee index 25f9c31aa..9daf0dc73 100644 --- a/spec/workspace-view-spec.coffee +++ b/spec/workspace-view-spec.coffee @@ -457,6 +457,8 @@ describe "WorkspaceView", -> describe "window:toggle-invisibles event", -> it "shows/hides invisibles in all open and future editors", -> + spyOn(Pane.prototype, "promptToSaveItem").andReturn 0 + atom.workspaceView.height(200) atom.workspaceView.attachToDom() rightEditor = atom.workspaceView.getActiveView() From 04ad048e1f1e698e35d2e37fe91f50bec7258dfd Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 12 Dec 2013 08:15:32 -0800 Subject: [PATCH 12/37] :non-potable_water Upgrade to space-pen@2.0.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 70f24b368..77b89f65c 100644 --- a/package.json +++ b/package.json @@ -42,7 +42,7 @@ "scandal": "0.8.0", "season": "0.14.0", "semver": "1.1.4", - "space-pen": "2.0.1", + "space-pen": "2.0.2", "telepath": "0.70.0", "temp": "0.5.0", "underscore-plus": "0.5.0" From 63cac904ae254f4d4bb39dd8e1750d6b5c7b3f7e Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 12 Dec 2013 08:51:02 -0800 Subject: [PATCH 13/37] Export telepath Model --- exports/atom.coffee | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/exports/atom.coffee b/exports/atom.coffee index fd2e175e2..35a65c566 100644 --- a/exports/atom.coffee +++ b/exports/atom.coffee @@ -1,4 +1,4 @@ -{Document, Point, Range} = require 'telepath' +{Document, Model, Point, Range} = require 'telepath' module.exports = _: require 'underscore-plus' @@ -9,6 +9,7 @@ module.exports = File: require '../src/file' fs: require 'fs-plus' Git: require '../src/git' + Model: Model Point: Point Range: Range From 9fbfeb970bdc50b84e79a9e3237cfb21c8ea6d51 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 12 Dec 2013 09:03:23 -0800 Subject: [PATCH 14/37] Remove mixins already added by Model superclass --- src/project.coffee | 6 ++---- src/text-buffer.coffee | 4 ---- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/src/project.coffee b/src/project.coffee index 27f3c0880..eae064fd6 100644 --- a/src/project.coffee +++ b/src/project.coffee @@ -4,11 +4,10 @@ url = require 'url' _ = require 'underscore-plus' fs = require 'fs-plus' Q = require 'q' -telepath = require 'telepath' +{Model} = require 'telepath' TextBuffer = require './text-buffer' Editor = require './editor' -{Emitter} = require 'emissary' Directory = require './directory' Task = require './task' Git = require './git' @@ -18,8 +17,7 @@ Git = require './git' # Ultimately, a project is a git directory that's been opened. It's a collection # of directories and files that you can operate on. module.exports = -class Project extends telepath.Model - Emitter.includeInto(this) +class Project extends Model @properties buffers: [] diff --git a/src/text-buffer.coffee b/src/text-buffer.coffee index d84ee24da..665b7d02d 100644 --- a/src/text-buffer.coffee +++ b/src/text-buffer.coffee @@ -1,5 +1,4 @@ _ = require 'underscore-plus' -{Emitter, Subscriber} = require 'emissary' Q = require 'q' {P} = require 'scandal' telepath = require 'telepath' @@ -14,9 +13,6 @@ File = require './file' # the case, as a `TextBuffer` could be an unsaved chunk of text. module.exports = class TextBuffer extends telepath.Model - Emitter.includeInto(this) - Subscriber.includeInto(this) - @properties text: -> new telepath.String('', replicated: false) filePath: null From 787b6fb67719ff41bd563a11165aebe2e726355e Mon Sep 17 00:00:00 2001 From: probablycorey Date: Thu, 12 Dec 2013 10:09:41 -0800 Subject: [PATCH 15/37] Revert "Don't pop-up save dialog in specs" This reverts commit e0ad22d0bd6661c17df10b58d5925f7b21fede55. --- spec/editor-view-spec.coffee | 3 --- spec/workspace-view-spec.coffee | 2 -- 2 files changed, 5 deletions(-) diff --git a/spec/editor-view-spec.coffee b/spec/editor-view-spec.coffee index f1ec0d19c..bd4f71dcf 100644 --- a/spec/editor-view-spec.coffee +++ b/spec/editor-view-spec.coffee @@ -1,6 +1,5 @@ WorkspaceView = require '../src/workspace-view' EditorView = require '../src/editor-view' -Pane = require '../src/pane' {$, $$} = require '../src/space-pen-extensions' _ = require 'underscore-plus' fs = require 'fs-plus' @@ -2751,8 +2750,6 @@ describe "EditorView", -> describe "when the editor view is attached but invisible", -> describe "when the editor view's text is changed", -> it "redraws the editor view when it is next shown", -> - spyOn(Pane.prototype, "promptToSaveItem").andReturn false - atom.workspaceView = new WorkspaceView atom.workspaceView.openSync('sample.js') atom.workspaceView.attachToDom() diff --git a/spec/workspace-view-spec.coffee b/spec/workspace-view-spec.coffee index 6c8a6e3d2..a8449cc76 100644 --- a/spec/workspace-view-spec.coffee +++ b/spec/workspace-view-spec.coffee @@ -457,8 +457,6 @@ describe "WorkspaceView", -> describe "window:toggle-invisibles event", -> it "shows/hides invisibles in all open and future editors", -> - spyOn(Pane.prototype, "promptToSaveItem").andReturn 0 - atom.workspaceView.height(200) atom.workspaceView.attachToDom() rightEditor = atom.workspaceView.getActiveView() From 1f69963982d0b93d2f45b6e802a3667aeab3a29d Mon Sep 17 00:00:00 2001 From: Ben Ogle Date: Wed, 11 Dec 2013 17:42:35 -0800 Subject: [PATCH 16/37] Apply text to buffer via diff on reload Previously, it would blindly read from disk on reload, and set the text into the editor. This was problematic as it would mess with markers and folds. No longer. Fixes #1285 and fixes atom/bookmarks#3 --- package.json | 1 + spec/text-buffer-spec.coffee | 72 +++++++++++++++++++++++++++++++++++- src/text-buffer.coffee | 55 ++++++++++++++++++++++++++- 3 files changed, 125 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 77b89f65c..28e4eacc7 100644 --- a/package.json +++ b/package.json @@ -23,6 +23,7 @@ "clear-cut": "0.2.0", "coffee-script": "1.6.3", "coffeestack": "0.6.0", + "diff": "git://github.com/benogle/jsdiff.git", "emissary": "0.19.0", "first-mate": "0.5.0", "fs-plus": "0.11.0", diff --git a/spec/text-buffer-spec.coffee b/spec/text-buffer-spec.coffee index 31066cd5b..963edd932 100644 --- a/spec/text-buffer-spec.coffee +++ b/spec/text-buffer-spec.coffee @@ -113,10 +113,17 @@ describe 'TextBuffer', -> runs -> [event] = changeHandler.argsForCall[0] - expect(event.oldRange).toEqual [[0, 0], [0, 5]] + expect(event.oldRange).toEqual [[0, 0], [0, 0]] expect(event.newRange).toEqual [[0, 0], [0, 6]] - expect(event.oldText).toBe "first" + expect(event.oldText).toBe "" expect(event.newText).toBe "second" + + [event] = changeHandler.argsForCall[1] + expect(event.oldRange).toEqual [[0, 6], [0, 11]] + expect(event.newRange).toEqual [[0, 6], [0, 6]] + expect(event.oldText).toBe "first" + expect(event.newText).toBe "" + expect(buffer.isModified()).toBeFalsy() describe "when the buffer's memory contents differ from the *previous* disk contents", -> @@ -454,6 +461,67 @@ describe 'TextBuffer', -> expect(event.oldRange).toEqual expectedPreRange expect(event.newRange).toEqual [[0, 0], [1, 14]] + describe ".setTextViaDiff(text)", -> + it "changes the entire contents of the buffer with smaller content with no newline at the end", -> + newText = "I know you are.\nBut what am I?" + buffer.setTextViaDiff(newText) + expect(buffer.getText()).toBe newText + + it "changes the entire contents of the buffer with smaller content with newline at the end", -> + newText = "I know you are.\nBut what am I?\n" + buffer.setTextViaDiff(newText) + expect(buffer.getText()).toBe newText + + it "changes a few lines at the beginning in the buffer", -> + newText = buffer.getText().replace(/function/g, 'omgwow') + buffer.setTextViaDiff(newText) + expect(buffer.getText()).toBe newText + + it "changes a few lines in the middle of the buffer", -> + newText = buffer.getText().replace(/shift/g, 'omgwow') + buffer.setTextViaDiff(newText) + expect(buffer.getText()).toBe newText + + it "adds a newline at the end", -> + newText = buffer.getText() + '\n' + buffer.setTextViaDiff(newText) + expect(buffer.getText()).toBe newText + + it "changes all with no newlines", -> + buffer.setText('BUFFER CHANGE') + newText = 'DISK CHANGE' + buffer.setTextViaDiff(newText) + expect(buffer.getText()).toBe newText + + describe "with windows newlines", -> + beforeEach -> + buffer.setText(buffer.getText().replace(/\n/g, '\r\n')) + + it "adds a newline at the end", -> + newText = buffer.getText() + '\r\n' + buffer.setTextViaDiff(newText) + expect(buffer.getText()).toBe newText + + it "changes the entire contents of the buffer with smaller content with no newline at the end", -> + newText = "I know you are.\r\nBut what am I?" + buffer.setTextViaDiff(newText) + expect(buffer.getText()).toBe newText + + it "changes the entire contents of the buffer with smaller content with newline at the end", -> + newText = "I know you are.\r\nBut what am I?\r\n" + buffer.setTextViaDiff(newText) + expect(buffer.getText()).toBe newText + + it "changes a few lines at the beginning in the buffer", -> + newText = buffer.getText().replace(/function/g, 'omgwow') + buffer.setTextViaDiff(newText) + expect(buffer.getText()).toBe newText + + it "changes a few lines in the middle of the buffer", -> + newText = buffer.getText().replace(/shift/g, 'omgwow') + buffer.setTextViaDiff(newText) + expect(buffer.getText()).toBe newText + describe ".save()", -> saveBuffer = null diff --git a/src/text-buffer.coffee b/src/text-buffer.coffee index 665b7d02d..51cad7723 100644 --- a/src/text-buffer.coffee +++ b/src/text-buffer.coffee @@ -1,4 +1,5 @@ _ = require 'underscore-plus' +diff = require 'diff' Q = require 'q' {P} = require 'scandal' telepath = require 'telepath' @@ -133,7 +134,7 @@ class TextBuffer extends telepath.Model # Sets the buffer's content to the cached disk contents reload: -> @emit 'will-reload' - @setText(@cachedDiskContents) + @setTextViaDiff(@cachedDiskContents) @emitModifiedStatusChanged(false) @emit 'reloaded' @@ -198,6 +199,12 @@ class TextBuffer extends telepath.Model setText: (text) -> @change(@getRange(), text, normalizeLineEndings: false) + # Replaces the current buffer contents. Only apply the differences. + # + # text - A {String} containing the new buffer contents. + setTextViaDiff: (text) -> + @applyDifferences(text) + # Gets the range of the buffer contents. # # Returns a new {Range}, from `[0, 0]` to the end of the buffer. @@ -667,3 +674,49 @@ class TextBuffer extends telepath.Model for row in [start..end] line = @lineForRow(row) console.log row, line, line.length + + applyDifferences: (newText) -> + currentText = @getText() + return if currentText == newText + + endsWithNewline = (str) -> + /[\r\n]+$/g.test(str) + + computeBufferColumn = (str) -> + newlineIndex = Math.max(str.lastIndexOf('\n'), str.lastIndexOf('\r')) + if endsWithNewline(str) + 0 + else if newlineIndex == -1 + str.length + else + str.length - newlineIndex - 1 + + @transact => + bufferRow = 0 + bufferColumn = 0 + startPosition = [0, 0] + + lineDiff = diff.diffLines(currentText, newText) + changeOptions = normalizeLineEndings: false + + for change in lineDiff + numberLines = change.value.match(/\n/g)?.length ? 0 + startPosition[0] = bufferRow + startPosition[1] = bufferColumn + + if change.added + @change([startPosition, startPosition], change.value, changeOptions) + bufferRow += numberLines + bufferColumn = computeBufferColumn(change.value) + + else if change.removed + endBufferRow = bufferRow + numberLines + endBufferColumn = bufferColumn + computeBufferColumn(change.value) + @change([startPosition, [endBufferRow, endBufferColumn]], '', changeOptions) + + else + bufferRow += numberLines + bufferColumn = computeBufferColumn(change.value) + + # console.log 'after', bufferRow, bufferColumn, change + # console.log @getText() From ed745d20721c41dc1460aedde7253c5d023f71d9 Mon Sep 17 00:00:00 2001 From: Ben Ogle Date: Wed, 11 Dec 2013 17:44:00 -0800 Subject: [PATCH 17/37] Remove log lines --- src/text-buffer.coffee | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/text-buffer.coffee b/src/text-buffer.coffee index 51cad7723..6536b2238 100644 --- a/src/text-buffer.coffee +++ b/src/text-buffer.coffee @@ -717,6 +717,3 @@ class TextBuffer extends telepath.Model else bufferRow += numberLines bufferColumn = computeBufferColumn(change.value) - - # console.log 'after', bufferRow, bufferColumn, change - # console.log @getText() From 60498616b79a995b0e059c5573a167f7c829c5ed Mon Sep 17 00:00:00 2001 From: Ben Ogle Date: Wed, 11 Dec 2013 17:48:33 -0800 Subject: [PATCH 18/37] numberLines -> lineCount --- src/text-buffer.coffee | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/text-buffer.coffee b/src/text-buffer.coffee index 6536b2238..160076c05 100644 --- a/src/text-buffer.coffee +++ b/src/text-buffer.coffee @@ -700,20 +700,20 @@ class TextBuffer extends telepath.Model changeOptions = normalizeLineEndings: false for change in lineDiff - numberLines = change.value.match(/\n/g)?.length ? 0 + lineCount = change.value.match(/\n/g)?.length ? 0 startPosition[0] = bufferRow startPosition[1] = bufferColumn if change.added @change([startPosition, startPosition], change.value, changeOptions) - bufferRow += numberLines + bufferRow += lineCount bufferColumn = computeBufferColumn(change.value) else if change.removed - endBufferRow = bufferRow + numberLines + endBufferRow = bufferRow + lineCount endBufferColumn = bufferColumn + computeBufferColumn(change.value) @change([startPosition, [endBufferRow, endBufferColumn]], '', changeOptions) else - bufferRow += numberLines + bufferRow += lineCount bufferColumn = computeBufferColumn(change.value) From 8d1d64d9d3149636de45cd0995cb37019cf55413 Mon Sep 17 00:00:00 2001 From: Ben Ogle Date: Wed, 11 Dec 2013 17:51:19 -0800 Subject: [PATCH 19/37] bufferRow -> row --- src/text-buffer.coffee | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/text-buffer.coffee b/src/text-buffer.coffee index 160076c05..4d42ba28b 100644 --- a/src/text-buffer.coffee +++ b/src/text-buffer.coffee @@ -692,8 +692,8 @@ class TextBuffer extends telepath.Model str.length - newlineIndex - 1 @transact => - bufferRow = 0 - bufferColumn = 0 + row = 0 + column = 0 startPosition = [0, 0] lineDiff = diff.diffLines(currentText, newText) @@ -701,19 +701,19 @@ class TextBuffer extends telepath.Model for change in lineDiff lineCount = change.value.match(/\n/g)?.length ? 0 - startPosition[0] = bufferRow - startPosition[1] = bufferColumn + startPosition[0] = row + startPosition[1] = column if change.added @change([startPosition, startPosition], change.value, changeOptions) - bufferRow += lineCount - bufferColumn = computeBufferColumn(change.value) + row += lineCount + column = computeBufferColumn(change.value) else if change.removed - endBufferRow = bufferRow + lineCount - endBufferColumn = bufferColumn + computeBufferColumn(change.value) + endBufferRow = row + lineCount + endBufferColumn = column + computeBufferColumn(change.value) @change([startPosition, [endBufferRow, endBufferColumn]], '', changeOptions) else - bufferRow += lineCount - bufferColumn = computeBufferColumn(change.value) + row += lineCount + column = computeBufferColumn(change.value) From 5d46d7a88118b80df24cf9b3d7ada168f813fc21 Mon Sep 17 00:00:00 2001 From: Ben Ogle Date: Wed, 11 Dec 2013 17:53:54 -0800 Subject: [PATCH 20/37] :lipstick: --- src/text-buffer.coffee | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/text-buffer.coffee b/src/text-buffer.coffee index 4d42ba28b..b3a60c09f 100644 --- a/src/text-buffer.coffee +++ b/src/text-buffer.coffee @@ -694,25 +694,25 @@ class TextBuffer extends telepath.Model @transact => row = 0 column = 0 - startPosition = [0, 0] + currentPosition = [0, 0] lineDiff = diff.diffLines(currentText, newText) changeOptions = normalizeLineEndings: false for change in lineDiff lineCount = change.value.match(/\n/g)?.length ? 0 - startPosition[0] = row - startPosition[1] = column + currentPosition[0] = row + currentPosition[1] = column if change.added - @change([startPosition, startPosition], change.value, changeOptions) + @change([currentPosition, currentPosition], change.value, changeOptions) row += lineCount column = computeBufferColumn(change.value) else if change.removed - endBufferRow = row + lineCount - endBufferColumn = column + computeBufferColumn(change.value) - @change([startPosition, [endBufferRow, endBufferColumn]], '', changeOptions) + endRow = row + lineCount + endColumn = column + computeBufferColumn(change.value) + @change([currentPosition, [endRow, endColumn]], '', changeOptions) else row += lineCount From 7111961929cdbda901aa4c5a7b71ab8dfcab0ffa Mon Sep 17 00:00:00 2001 From: Ben Ogle Date: Wed, 11 Dec 2013 17:56:38 -0800 Subject: [PATCH 21/37] Move function into setTextViaDiff() --- src/text-buffer.coffee | 85 ++++++++++++++++++++---------------------- 1 file changed, 41 insertions(+), 44 deletions(-) diff --git a/src/text-buffer.coffee b/src/text-buffer.coffee index b3a60c09f..6d3542eec 100644 --- a/src/text-buffer.coffee +++ b/src/text-buffer.coffee @@ -203,7 +203,47 @@ class TextBuffer extends telepath.Model # # text - A {String} containing the new buffer contents. setTextViaDiff: (text) -> - @applyDifferences(text) + currentText = @getText() + return if currentText == text + + endsWithNewline = (str) -> + /[\r\n]+$/g.test(str) + + computeBufferColumn = (str) -> + newlineIndex = Math.max(str.lastIndexOf('\n'), str.lastIndexOf('\r')) + if endsWithNewline(str) + 0 + else if newlineIndex == -1 + str.length + else + str.length - newlineIndex - 1 + + @transact => + row = 0 + column = 0 + currentPosition = [0, 0] + + lineDiff = diff.diffLines(currentText, text) + changeOptions = normalizeLineEndings: false + + for change in lineDiff + lineCount = change.value.match(/\n/g)?.length ? 0 + currentPosition[0] = row + currentPosition[1] = column + + if change.added + @change([currentPosition, currentPosition], change.value, changeOptions) + row += lineCount + column = computeBufferColumn(change.value) + + else if change.removed + endRow = row + lineCount + endColumn = column + computeBufferColumn(change.value) + @change([currentPosition, [endRow, endColumn]], '', changeOptions) + + else + row += lineCount + column = computeBufferColumn(change.value) # Gets the range of the buffer contents. # @@ -674,46 +714,3 @@ class TextBuffer extends telepath.Model for row in [start..end] line = @lineForRow(row) console.log row, line, line.length - - applyDifferences: (newText) -> - currentText = @getText() - return if currentText == newText - - endsWithNewline = (str) -> - /[\r\n]+$/g.test(str) - - computeBufferColumn = (str) -> - newlineIndex = Math.max(str.lastIndexOf('\n'), str.lastIndexOf('\r')) - if endsWithNewline(str) - 0 - else if newlineIndex == -1 - str.length - else - str.length - newlineIndex - 1 - - @transact => - row = 0 - column = 0 - currentPosition = [0, 0] - - lineDiff = diff.diffLines(currentText, newText) - changeOptions = normalizeLineEndings: false - - for change in lineDiff - lineCount = change.value.match(/\n/g)?.length ? 0 - currentPosition[0] = row - currentPosition[1] = column - - if change.added - @change([currentPosition, currentPosition], change.value, changeOptions) - row += lineCount - column = computeBufferColumn(change.value) - - else if change.removed - endRow = row + lineCount - endColumn = column + computeBufferColumn(change.value) - @change([currentPosition, [endRow, endColumn]], '', changeOptions) - - else - row += lineCount - column = computeBufferColumn(change.value) From 4dbca94d32a29055cbe4b8c573a4c062599aaa08 Mon Sep 17 00:00:00 2001 From: Ben Ogle Date: Wed, 11 Dec 2013 18:00:13 -0800 Subject: [PATCH 22/37] spec :lipstick: --- spec/text-buffer-spec.coffee | 53 ++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 26 deletions(-) diff --git a/spec/text-buffer-spec.coffee b/spec/text-buffer-spec.coffee index 963edd932..0aaf9a3b5 100644 --- a/spec/text-buffer-spec.coffee +++ b/spec/text-buffer-spec.coffee @@ -462,37 +462,38 @@ describe 'TextBuffer', -> expect(event.newRange).toEqual [[0, 0], [1, 14]] describe ".setTextViaDiff(text)", -> - it "changes the entire contents of the buffer with smaller content with no newline at the end", -> - newText = "I know you are.\nBut what am I?" - buffer.setTextViaDiff(newText) - expect(buffer.getText()).toBe newText - - it "changes the entire contents of the buffer with smaller content with newline at the end", -> - newText = "I know you are.\nBut what am I?\n" - buffer.setTextViaDiff(newText) - expect(buffer.getText()).toBe newText - - it "changes a few lines at the beginning in the buffer", -> - newText = buffer.getText().replace(/function/g, 'omgwow') - buffer.setTextViaDiff(newText) - expect(buffer.getText()).toBe newText - - it "changes a few lines in the middle of the buffer", -> - newText = buffer.getText().replace(/shift/g, 'omgwow') - buffer.setTextViaDiff(newText) - expect(buffer.getText()).toBe newText - - it "adds a newline at the end", -> - newText = buffer.getText() + '\n' - buffer.setTextViaDiff(newText) - expect(buffer.getText()).toBe newText - - it "changes all with no newlines", -> + it "can change the entire contents of the buffer when there are no newlines", -> buffer.setText('BUFFER CHANGE') newText = 'DISK CHANGE' buffer.setTextViaDiff(newText) expect(buffer.getText()).toBe newText + describe "with standard newlines", -> + it "can change the entire contents of the buffer with no newline at the end", -> + newText = "I know you are.\nBut what am I?" + buffer.setTextViaDiff(newText) + expect(buffer.getText()).toBe newText + + it "can change the entire contents of the buffer with a newline at the end", -> + newText = "I know you are.\nBut what am I?\n" + buffer.setTextViaDiff(newText) + expect(buffer.getText()).toBe newText + + it "can change a few lines at the beginning in the buffer", -> + newText = buffer.getText().replace(/function/g, 'omgwow') + buffer.setTextViaDiff(newText) + expect(buffer.getText()).toBe newText + + it "can change a few lines in the middle of the buffer", -> + newText = buffer.getText().replace(/shift/g, 'omgwow') + buffer.setTextViaDiff(newText) + expect(buffer.getText()).toBe newText + + it "can adds a newline at the end", -> + newText = buffer.getText() + '\n' + buffer.setTextViaDiff(newText) + expect(buffer.getText()).toBe newText + describe "with windows newlines", -> beforeEach -> buffer.setText(buffer.getText().replace(/\n/g, '\r\n')) From 4ffa5bb90e1b6b9708cb989ad6b4d2d6115e3af7 Mon Sep 17 00:00:00 2001 From: Ben Ogle Date: Wed, 11 Dec 2013 18:22:14 -0800 Subject: [PATCH 23/37] Make this fn private. --- src/text-buffer.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/text-buffer.coffee b/src/text-buffer.coffee index 6d3542eec..76f897e3c 100644 --- a/src/text-buffer.coffee +++ b/src/text-buffer.coffee @@ -199,7 +199,7 @@ class TextBuffer extends telepath.Model setText: (text) -> @change(@getRange(), text, normalizeLineEndings: false) - # Replaces the current buffer contents. Only apply the differences. + # Private: Replaces the current buffer contents. Only apply the differences. # # text - A {String} containing the new buffer contents. setTextViaDiff: (text) -> From f414c0955b933458b91179ab6cafbdc05650fefc Mon Sep 17 00:00:00 2001 From: probablycorey Date: Thu, 12 Dec 2013 10:35:11 -0800 Subject: [PATCH 24/37] Specs don't prompt to save editors by default. --- spec/editor-spec.coffee | 1 + spec/pane-spec.coffee | 1 + spec/spec-helper.coffee | 2 ++ 3 files changed, 4 insertions(+) diff --git a/spec/editor-spec.coffee b/spec/editor-spec.coffee index 85693921d..afa9c1f33 100644 --- a/spec/editor-spec.coffee +++ b/spec/editor-spec.coffee @@ -2614,6 +2614,7 @@ describe "Editor", -> describe ".shouldPromptToSave()", -> it "returns false when an edit session's buffer is in use by more than one session", -> + jasmine.unspy(editor, 'shouldPromptToSave') expect(editor.shouldPromptToSave()).toBeFalsy() buffer.setText('changed') expect(editor.shouldPromptToSave()).toBeTruthy() diff --git a/spec/pane-spec.coffee b/spec/pane-spec.coffee index e82ef9f97..d47d0687b 100644 --- a/spec/pane-spec.coffee +++ b/spec/pane-spec.coffee @@ -147,6 +147,7 @@ describe "Pane", -> describe "if the item is modified", -> beforeEach -> + jasmine.unspy(editor2, 'shouldPromptToSave') spyOn(editor2, 'save') spyOn(editor2, 'saveAs') diff --git a/spec/spec-helper.coffee b/spec/spec-helper.coffee index 74d95c431..302aeeb0c 100644 --- a/spec/spec-helper.coffee +++ b/spec/spec-helper.coffee @@ -9,6 +9,7 @@ Keymap = require '../src/keymap' Config = require '../src/config' {Point} = require 'telepath' Project = require '../src/project' +Editor = require '../src/editor' EditorView = require '../src/editor-view' TokenizedBuffer = require '../src/tokenized-buffer' pathwatcher = require 'pathwatcher' @@ -92,6 +93,7 @@ beforeEach -> spyOn(window, "setTimeout").andCallFake window.fakeSetTimeout spyOn(window, "clearTimeout").andCallFake window.fakeClearTimeout spyOn(File.prototype, "detectResurrectionAfterDelay").andCallFake -> @detectResurrection() + spyOn(Editor.prototype, "shouldPromptToSave").andReturn false # make tokenization synchronous TokenizedBuffer.prototype.chunkSize = Infinity From 0ccaf9049f22568ffc36ae0a04b1225dfb3a7cb3 Mon Sep 17 00:00:00 2001 From: Ben Ogle Date: Thu, 12 Dec 2013 11:24:46 -0800 Subject: [PATCH 25/37] Upgrade to dev-live-reload@0.19.0 Reload all themes when syntax variables change --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 28e4eacc7..dbc5931fc 100644 --- a/package.json +++ b/package.json @@ -88,7 +88,7 @@ "bracket-matcher": "0.15.0", "command-logger": "0.8.0", "command-palette": "0.13.0", - "dev-live-reload": "0.18.0", + "dev-live-reload": "0.19.0", "editor-stats": "0.8.0", "exception-reporting": "0.8.0", "feedback": "0.16.0", From f6d1647021a542d4bfefce7c341e8bdbe0902352 Mon Sep 17 00:00:00 2001 From: Ben Ogle Date: Thu, 12 Dec 2013 11:56:54 -0800 Subject: [PATCH 26/37] Upgrade git diff and all the themes with new colors. --- package.json | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index dbc5931fc..e8c05c5d2 100644 --- a/package.json +++ b/package.json @@ -74,12 +74,13 @@ "github-releases": "~0.2.0" }, "packageDependencies": { - "atom-dark-syntax": "0.8.0", + "atom-dark-syntax": "0.10.0", "atom-dark-ui": "0.17.0", - "atom-light-syntax": "0.9.0", + "atom-light-syntax": "0.10.0", "atom-light-ui": "0.16.0", - "base16-tomorrow-dark-theme": "0.7.0", - "solarized-dark-syntax": "0.5.0", + "base16-tomorrow-dark-theme": "0.8.0", + "solarized-dark-syntax": "0.6.0", + "solarized-light-syntax": "0.2.0", "archive-view": "0.16.0", "autocomplete": "0.18.0", "autoflow": "0.11.0", @@ -95,7 +96,7 @@ "find-and-replace": "0.58.0", "fuzzy-finder": "0.28.0", "gists": "0.13.0", - "git-diff": "0.20.0", + "git-diff": "0.21.0", "github-sign-in": "0.15.0", "go-to-line": "0.12.0", "grammar-selector": "0.13.0", From f439b04978278fc1b16f961c393bd3ef8fbd9637 Mon Sep 17 00:00:00 2001 From: probablycorey Date: Thu, 12 Dec 2013 13:37:56 -0800 Subject: [PATCH 27/37] Update tree-view and find-and-replace packages --- package.json | 4 ++-- src/pane.coffee | 21 ++++++++++++--------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/package.json b/package.json index 28e4eacc7..343622357 100644 --- a/package.json +++ b/package.json @@ -92,7 +92,7 @@ "editor-stats": "0.8.0", "exception-reporting": "0.8.0", "feedback": "0.16.0", - "find-and-replace": "0.58.0", + "find-and-replace": "0.59.0", "fuzzy-finder": "0.28.0", "gists": "0.13.0", "git-diff": "0.20.0", @@ -116,7 +116,7 @@ "terminal": "0.23.0", "timecop": "0.11.0", "to-the-hubs": "0.15.0", - "tree-view": "0.44.0", + "tree-view": "0.45.0", "visual-bell": "0.6.0", "welcome": "0.3.0", "whitespace": "0.10.0", diff --git a/src/pane.coffee b/src/pane.coffee index 288a65522..3b3c46e95 100644 --- a/src/pane.coffee +++ b/src/pane.coffee @@ -34,16 +34,17 @@ class Pane extends View @items = [] if args[0] instanceof telepath.Document @state = args[0] - @state.get('items').each (item) => - if item = atom.deserializers.deserialize(item) - item?.created?() - @addItem(item, @items.length) + @items = _.compact @state.get('items').map (item) -> + item = atom.deserializers.deserialize(item) + item?.created?() + item else - items = args + @items = args @state = atom.site.createDocument deserializer: 'Pane' - items: items.map (item) -> item.getState?() ? item.serialize() - items.forEach (item) => @addItem(item, @items.length) + items: @items.map (item) -> item.getState?() ? item.serialize() + + @handleItemEvents(item) for item in @items @subscribe @state.get('items'), 'changed', ({index, removedValues, insertedValues, siteId}) => return if siteId is @state.siteId @@ -190,10 +191,12 @@ class Pane extends View @state.get('items').splice(index, 0, item.getState?() ? item.serialize()) if options.updateState ? true @items.splice(index, 0, item) @trigger 'pane:item-added', [item, index] - if item.on - @subscribe item, 'destroyed', => @destroyItem(item) + @handleItemEvents(item) item + handleItemEvents: (item) -> + @subscribe item, 'destroyed', => @destroyItem(item) if _.isFunction(item.on) + # Public: Remove the currently active item. destroyActiveItem: => @destroyItem(@activeItem) From 58bf19cc83ee08b937a84a36749b484b414451c5 Mon Sep 17 00:00:00 2001 From: probablycorey Date: Thu, 12 Dec 2013 14:00:21 -0800 Subject: [PATCH 28/37] Fix syntax error --- src/pane.coffee | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/pane.coffee b/src/pane.coffee index 3b3c46e95..c122f11ff 100644 --- a/src/pane.coffee +++ b/src/pane.coffee @@ -195,7 +195,8 @@ class Pane extends View item handleItemEvents: (item) -> - @subscribe item, 'destroyed', => @destroyItem(item) if _.isFunction(item.on) + if _.isFunction(item.on) + @subscribe item, 'destroyed', => @destroyItem(item) # Public: Remove the currently active item. destroyActiveItem: => @@ -204,7 +205,7 @@ class Pane extends View # Public: Remove the specified item. destroyItem: (item) -> - @unsubscribe(item) if item.off + @unsubscribe(item) if _.isFunction(item.off) @trigger 'pane:before-item-destroyed', [item] if @promptToSaveItem(item) From 90f3726c5c879de04ddac556dc1061f9bf063437 Mon Sep 17 00:00:00 2001 From: probablycorey Date: Thu, 12 Dec 2013 14:27:44 -0800 Subject: [PATCH 29/37] Fix window specs --- spec/window-spec.coffee | 2 ++ src/pane.coffee | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/spec/window-spec.coffee b/spec/window-spec.coffee index 68f9adeb2..d7b357271 100644 --- a/spec/window-spec.coffee +++ b/spec/window-spec.coffee @@ -1,5 +1,6 @@ {$, $$, fs} = require 'atom' path = require 'path' +Editor = require '../src/editor' WindowEventHandler = require '../src/window-event-handler' describe "Window", -> @@ -55,6 +56,7 @@ describe "Window", -> [beforeUnloadEvent] = [] beforeEach -> + jasmine.unspy(Editor.prototype, "shouldPromptToSave") beforeUnloadEvent = $.Event(new Event('beforeunload')) describe "when pane items are are modified", -> diff --git a/src/pane.coffee b/src/pane.coffee index c122f11ff..326c3a2af 100644 --- a/src/pane.coffee +++ b/src/pane.coffee @@ -196,7 +196,8 @@ class Pane extends View handleItemEvents: (item) -> if _.isFunction(item.on) - @subscribe item, 'destroyed', => @destroyItem(item) + @subscribe item, 'destroyed', => + @destroyItem(item) if @state.isAlive() # Public: Remove the currently active item. destroyActiveItem: => From e1d35ed90f5b2609f7aa4c7bca9a00b111dce4ba Mon Sep 17 00:00:00 2001 From: Ben Ogle Date: Thu, 12 Dec 2013 15:44:28 -0800 Subject: [PATCH 30/37] Upgrade dev-live-reload@0.20.0 Fix issue with reloading on changes to variable files --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index ba0158fe5..0b8bf7aee 100644 --- a/package.json +++ b/package.json @@ -89,7 +89,7 @@ "bracket-matcher": "0.15.0", "command-logger": "0.8.0", "command-palette": "0.13.0", - "dev-live-reload": "0.19.0", + "dev-live-reload": "0.20.0", "editor-stats": "0.8.0", "exception-reporting": "0.8.0", "feedback": "0.16.0", From ae72d4ad56c9a89ef42e6974cecb6d5d76047b39 Mon Sep 17 00:00:00 2001 From: Matt Colyer Date: Thu, 12 Dec 2013 16:41:09 -0800 Subject: [PATCH 31/37] Upgrade exception-reporting@0.9.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 0b8bf7aee..b6ca4ea69 100644 --- a/package.json +++ b/package.json @@ -91,7 +91,7 @@ "command-palette": "0.13.0", "dev-live-reload": "0.20.0", "editor-stats": "0.8.0", - "exception-reporting": "0.8.0", + "exception-reporting": "0.9.0", "feedback": "0.16.0", "find-and-replace": "0.59.0", "fuzzy-finder": "0.28.0", From 75cee638bc5037a45db8ff10c0bbb2f805b3e4b6 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Thu, 12 Dec 2013 15:56:44 -0800 Subject: [PATCH 32/37] Protect from exceptions when attaching editor views w/ dead editors Addresses #1306 We still need to know why this is happening, so I left an exception in non-release builds. Since the pane system is about to change a lot I think this is good enough for now. --- src/editor-view.coffee | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/editor-view.coffee b/src/editor-view.coffee index fb1540d61..67a5d3ce7 100644 --- a/src/editor-view.coffee +++ b/src/editor-view.coffee @@ -780,6 +780,14 @@ class EditorView extends View afterAttach: (onDom) -> return unless onDom + + # TODO: Remove this guard when we understand why this is happening + unless @editor.isAlive() + if atom.isReleasedVersion() + return + else + throw new Error("Assertion failure: EditorView is getting attached to a dead editor. Why?") + @redraw() if @redrawOnReattach return if @attached @attached = true From 8367b020ecc9c388f6242e0e8a7ff59c197c364f Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 12 Dec 2013 17:41:50 -0800 Subject: [PATCH 33/37] Upgrade to editor-stats@0.9.0 for bug fix --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index b6ca4ea69..991e38364 100644 --- a/package.json +++ b/package.json @@ -90,7 +90,7 @@ "command-logger": "0.8.0", "command-palette": "0.13.0", "dev-live-reload": "0.20.0", - "editor-stats": "0.8.0", + "editor-stats": "0.9.0", "exception-reporting": "0.9.0", "feedback": "0.16.0", "find-and-replace": "0.59.0", From 07dee8838cbec904398279104e838ae0e9f4e6b4 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 12 Dec 2013 17:46:09 -0800 Subject: [PATCH 34/37] Upgrade to tree-view@0.46.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 991e38364..92ba7fa69 100644 --- a/package.json +++ b/package.json @@ -117,7 +117,7 @@ "terminal": "0.23.0", "timecop": "0.11.0", "to-the-hubs": "0.15.0", - "tree-view": "0.45.0", + "tree-view": "0.46.0", "visual-bell": "0.6.0", "welcome": "0.3.0", "whitespace": "0.10.0", From ee87c757edcf22e9f6b4c9fc40ebb587a69d430b Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 12 Dec 2013 18:04:25 -0800 Subject: [PATCH 35/37] Upgrade to tree-view@0.47.0 for arrow fix --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 92ba7fa69..1aab86a11 100644 --- a/package.json +++ b/package.json @@ -117,7 +117,7 @@ "terminal": "0.23.0", "timecop": "0.11.0", "to-the-hubs": "0.15.0", - "tree-view": "0.46.0", + "tree-view": "0.47.0", "visual-bell": "0.6.0", "welcome": "0.3.0", "whitespace": "0.10.0", From 87e325dce1075a4e4fa3df675d606a0f71a857e1 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 12 Dec 2013 18:05:36 -0800 Subject: [PATCH 36/37] Set body's visibility to hidden when unloading Previously the display was changed to none via $.hide() which accidentally affected the ability of package's to serialize DOM properties such as scrollTop since the value would always be zero when the display was none. The goal here is to just prevent a flicker when refreshing the editor window and setting visibility to hidden still accomplishes this. --- src/atom.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/atom.coffee b/src/atom.coffee index 9a586434c..a2f3d2df2 100644 --- a/src/atom.coffee +++ b/src/atom.coffee @@ -194,7 +194,7 @@ class Atom @menu.update() $(window).on 'unload', => - $(document.body).hide() + $(document.body).css('visibility', 'hidden') @unloadEditorWindow() false From 7b86891642188b0789f63deece9f8bba5a576fc6 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 12 Dec 2013 18:24:54 -0800 Subject: [PATCH 37/37] Upgrade to tree-view@0.48.0 for scroll left fixes --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 1aab86a11..9049211dd 100644 --- a/package.json +++ b/package.json @@ -117,7 +117,7 @@ "terminal": "0.23.0", "timecop": "0.11.0", "to-the-hubs": "0.15.0", - "tree-view": "0.47.0", + "tree-view": "0.48.0", "visual-bell": "0.6.0", "welcome": "0.3.0", "whitespace": "0.10.0",