From fed2372c30f90d7c4a4832ab86457a6cae5ec906 Mon Sep 17 00:00:00 2001 From: Matthew Dapena-Tretter Date: Tue, 4 Apr 2017 13:48:09 -0700 Subject: [PATCH] Don't store default locations This will probably be less confusing for developers experimenting with changing the default location. Also, we avoid storing extra info we don't really need. --- spec/workspace-spec.js | 27 +++++++++++++++++++++------ src/workspace.js | 12 +++++++++++- 2 files changed, 32 insertions(+), 7 deletions(-) diff --git a/spec/workspace-spec.js b/spec/workspace-spec.js index ba4d4496b..822b0ab5a 100644 --- a/spec/workspace-spec.js +++ b/spec/workspace-spec.js @@ -266,14 +266,13 @@ describe('Workspace', () => { const ITEM_URI = 'atom://test' const item = { getURI: () => ITEM_URI, - getDefaultLocation: jasmine.createSpy().andReturn('left'), + getDefaultLocation: () => 'left', getElement: () => document.createElement('div') } dock.getActivePane().addItem(item) expect(dock.getPaneItems()).toHaveLength(1) waitsForPromise(() => atom.workspace.open(ITEM_URI, {searchAllPanes: true})) runs(() => { - expect(item.getDefaultLocation).not.toHaveBeenCalled() expect(atom.workspace.getPaneItems()).toHaveLength(1) expect(dock.getPaneItems()).toHaveLength(1) expect(dock.getPaneItems()[0]).toBe(item) @@ -330,7 +329,7 @@ describe('Workspace', () => { const ITEM_URI = 'atom://test' const item = { getURI: () => ITEM_URI, - getDefaultLocation: jasmine.createSpy().andReturn('left'), + getDefaultLocation: () => 'left', getElement: () => document.createElement('div') } const opener = uri => uri === ITEM_URI ? item : null @@ -344,7 +343,6 @@ describe('Workspace', () => { runs(() => { expect(dock.getPaneItems()).toHaveLength(1) expect(dock.getPaneItems()[0]).toBe(item) - expect(item.getDefaultLocation).not.toHaveBeenCalled() }) }) }) @@ -2328,11 +2326,11 @@ i = /test/; #FIXME\ }) describe('when an item is moved', () => { - it('stores the new location', () => { + it("stores the new location if it's not the default", () => { const ITEM_URI = 'atom://test' const item = { getURI: () => ITEM_URI, - getDefaultLocation: jasmine.createSpy().andReturn('left'), + getDefaultLocation: () => 'left', getElement: () => document.createElement('div') } const centerPane = workspace.getActivePane() @@ -2342,6 +2340,23 @@ i = /test/; #FIXME\ centerPane.moveItemToPane(item, dockPane) expect(workspace.itemLocationStore.save).toHaveBeenCalledWith(ITEM_URI, 'right') }) + + it("clears the location if it's the default", () => { + const ITEM_URI = 'atom://test' + const item = { + getURI: () => ITEM_URI, + getDefaultLocation: () => 'right', + getElement: () => document.createElement('div') + } + const centerPane = workspace.getActivePane() + centerPane.addItem(item) + const dockPane = atom.workspace.getRightDock().getActivePane() + spyOn(workspace.itemLocationStore, 'save') + spyOn(workspace.itemLocationStore, 'delete') + centerPane.moveItemToPane(item, dockPane) + expect(workspace.itemLocationStore.delete).toHaveBeenCalledWith(ITEM_URI) + expect(workspace.itemLocationStore.save).not.toHaveBeenCalled() + }) }) }) diff --git a/src/workspace.js b/src/workspace.js index 3dd732d04..b5ee4616c 100644 --- a/src/workspace.js +++ b/src/workspace.js @@ -301,7 +301,17 @@ module.exports = class Workspace extends Model { if (typeof item.getURI === 'function') { const uri = item.getURI() if (uri != null) { - this.itemLocationStore.save(item.getURI(), paneContainer.getLocation()) + const location = paneContainer.getLocation() + let defaultLocation + if (typeof item.getDefaultLocation === 'function') { + defaultLocation = item.getDefaultLocation() + } + defaultLocation = defaultLocation || 'center' + if (location === defaultLocation) { + this.itemLocationStore.delete(item.getURI()) + } else { + this.itemLocationStore.save(item.getURI(), location) + } } } })