From 0015e026a29849f0011e7b3cbdc69244999bfedd Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Mon, 17 Apr 2017 11:34:45 -0700 Subject: [PATCH] Add Workspace.paneContainerForItem method --- spec/workspace-spec.js | 23 +++++++++++++++++++++++ src/workspace.js | 12 +++++++++++- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/spec/workspace-spec.js b/spec/workspace-spec.js index 36056ecea..7497c6940 100644 --- a/spec/workspace-spec.js +++ b/spec/workspace-spec.js @@ -984,6 +984,29 @@ describe('Workspace', () => { }) }) + describe('finding items in the workspace', () => { + it('can identify the pane and pane container for a given item or URI', () => { + const uri = 'atom://test-pane-for-item' + const item = { + element: document.createElement('div'), + getURI () { return uri } + } + + atom.workspace.getActivePane().activateItem(item) + expect(atom.workspace.paneForItem(item)).toBe(atom.workspace.getCenter().getActivePane()) + expect(atom.workspace.paneContainerForItem(item)).toBe(atom.workspace.getCenter()) + expect(atom.workspace.paneForURI(uri)).toBe(atom.workspace.getCenter().getActivePane()) + expect(atom.workspace.paneContainerForURI(uri)).toBe(atom.workspace.getCenter()) + + atom.workspace.getActivePane().destroyActiveItem() + atom.workspace.getLeftDock().getActivePane().activateItem(item) + expect(atom.workspace.paneForItem(item)).toBe(atom.workspace.getLeftDock().getActivePane()) + expect(atom.workspace.paneContainerForItem(item)).toBe(atom.workspace.getLeftDock()) + expect(atom.workspace.paneForURI(uri)).toBe(atom.workspace.getLeftDock().getActivePane()) + expect(atom.workspace.paneContainerForURI(uri)).toBe(atom.workspace.getLeftDock()) + }) + }) + describe('::hide(uri)', () => { let item const URI = 'atom://hide-test' diff --git a/src/workspace.js b/src/workspace.js index ccd11b0f2..cbf38602f 100644 --- a/src/workspace.js +++ b/src/workspace.js @@ -1373,6 +1373,16 @@ module.exports = class Workspace extends Model { return this.getPaneContainers().find(container => container.paneForURI(uri)) } + // Extended: Get the first pane container that contains the given item. + // + // * `item` the Item that the returned pane container must contain. + // + // Returns a {Dock}, the {WorkspaceCenter}, or `undefined` if no item exists + // with the given URI. + paneContainerForItem (uri) { + return this.getPaneContainers().find(container => container.paneForItem(uri)) + } + // Extended: Get the first {Pane} that contains an item with the given URI. // // * `uri` {String} uri @@ -1389,7 +1399,7 @@ module.exports = class Workspace extends Model { // Extended: Get the {Pane} containing the given item. // - // * `item` Item the returned pane contains. + // * `item` the Item that the returned pane must contain. // // Returns a {Pane} or `undefined` if no pane exists for the given item. paneForItem (item) {