From de47d3d439f228d4893201617d2c664415dc9d37 Mon Sep 17 00:00:00 2001 From: Jason Rudolph Date: Wed, 7 Jun 2017 15:32:30 -0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20Extract=20function:=20Pane::isIt?= =?UTF-8?q?emAllowed(item)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pane-container.js | 8 ++------ src/pane.coffee | 11 +++++++++++ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/pane-container.js b/src/pane-container.js index c4cb033a8..54cc4477d 100644 --- a/src/pane-container.js +++ b/src/pane-container.js @@ -214,9 +214,7 @@ class PaneContainer { moveActiveItemToPane (destPane) { const item = this.activePane.getActiveItem() - if (typeof item.getAllowedLocations === 'function' && !item.getAllowedLocations().includes(destPane.getContainer().getLocation())) { - return - } + if (!destPane.isItemAllowed(item)) { return } this.activePane.moveItemToPane(item, destPane) destPane.setActiveItem(item) @@ -225,9 +223,7 @@ class PaneContainer { copyActiveItemToPane (destPane) { const item = this.activePane.copyActiveItem() - if (typeof item.getAllowedLocations === 'function' && !item.getAllowedLocations().includes(destPane.getContainer().getLocation())) { - return - } + if (!destPane.isItemAllowed(item)) { return } destPane.activateItem(item) } diff --git a/src/pane.coffee b/src/pane.coffee index 31ee92f77..6713dbf2d 100644 --- a/src/pane.coffee +++ b/src/pane.coffee @@ -91,6 +91,17 @@ class Pane @container = container container.didAddPane({pane: this}) + # Private: Determine whether the given item is allowed to exist in this pane. + # + # * `item` the Item + # + # Returns a {Boolean}. + isItemAllowed: (item) -> + if (typeof item.getAllowedLocations isnt 'function') + true + else + item.getAllowedLocations().includes(@getContainer().getLocation()) + setFlexScale: (@flexScale) -> @emitter.emit 'did-change-flex-scale', @flexScale @flexScale