mirror of
https://github.com/atom/atom.git
synced 2026-02-06 12:44:59 -05:00
Refactor: Move directional pane fns to WorkspaceElement
This commit is contained in:
@@ -24,83 +24,5 @@ class PaneContainerElement extends HTMLElement
|
||||
hasFocus: ->
|
||||
this is document.activeElement or @contains(document.activeElement)
|
||||
|
||||
focusPaneViewAbove: ->
|
||||
@nearestPaneInDirection('above')?.focus()
|
||||
|
||||
focusPaneViewBelow: ->
|
||||
@nearestPaneInDirection('below')?.focus()
|
||||
|
||||
focusPaneViewOnLeft: ->
|
||||
@nearestPaneInDirection('left')?.focus()
|
||||
|
||||
focusPaneViewOnRight: ->
|
||||
@nearestPaneInDirection('right')?.focus()
|
||||
|
||||
moveActiveItemToPaneAbove: (params) ->
|
||||
@moveActiveItemToNearestPaneInDirection('above', params)
|
||||
|
||||
moveActiveItemToPaneBelow: (params) ->
|
||||
@moveActiveItemToNearestPaneInDirection('below', params)
|
||||
|
||||
moveActiveItemToPaneOnLeft: (params) ->
|
||||
@moveActiveItemToNearestPaneInDirection('left', params)
|
||||
|
||||
moveActiveItemToPaneOnRight: (params) ->
|
||||
@moveActiveItemToNearestPaneInDirection('right', params)
|
||||
|
||||
moveActiveItemToNearestPaneInDirection: (direction, params) ->
|
||||
destPane = @nearestPaneInDirection(direction)?.getModel()
|
||||
return unless destPane?
|
||||
if params?.keepOriginal
|
||||
@model.copyActiveItemToPane(destPane)
|
||||
else
|
||||
@model.moveActiveItemToPane(destPane)
|
||||
destPane.focus()
|
||||
|
||||
nearestPaneInDirection: (direction, pane = null) ->
|
||||
distance = (pointA, pointB) ->
|
||||
x = pointB.x - pointA.x
|
||||
y = pointB.y - pointA.y
|
||||
Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2))
|
||||
|
||||
pane = pane or atom.workspace.getActivePane()
|
||||
paneView = pane.getElement()
|
||||
box = @boundingBoxForPaneView(paneView)
|
||||
|
||||
visiblePaneContainers = atom.workspace.getPaneContainers()
|
||||
.filter (container) =>
|
||||
isCenter = container == atom.workspace.getCenter()
|
||||
isCenter or container.isVisible()
|
||||
|
||||
visiblePanes = _.flatten(visiblePaneContainers.map (container) => container.getPanes())
|
||||
|
||||
paneViews = visiblePanes
|
||||
.map (otherPane) =>
|
||||
otherPane.getElement()
|
||||
.filter (otherPaneView) =>
|
||||
otherBox = @boundingBoxForPaneView(otherPaneView)
|
||||
switch direction
|
||||
when 'left' then otherBox.right.x <= box.left.x
|
||||
when 'right' then otherBox.left.x >= box.right.x
|
||||
when 'above' then otherBox.bottom.y <= box.top.y
|
||||
when 'below' then otherBox.top.y >= box.bottom.y
|
||||
.sort (paneViewA, paneViewB) =>
|
||||
boxA = @boundingBoxForPaneView(paneViewA)
|
||||
boxB = @boundingBoxForPaneView(paneViewB)
|
||||
switch direction
|
||||
when 'left' then distance(box.left, boxA.right) - distance(box.left, boxB.right)
|
||||
when 'right' then distance(box.right, boxA.left) - distance(box.right, boxB.left)
|
||||
when 'above' then distance(box.top, boxA.bottom) - distance(box.top, boxB.bottom)
|
||||
when 'below' then distance(box.bottom, boxA.top) - distance(box.bottom, boxB.top)
|
||||
|
||||
paneViews[0]
|
||||
|
||||
boundingBoxForPaneView: (paneView) ->
|
||||
boundingBox = paneView.getBoundingClientRect()
|
||||
|
||||
left: {x: boundingBox.left, y: boundingBox.top}
|
||||
right: {x: boundingBox.right, y: boundingBox.top}
|
||||
top: {x: boundingBox.left, y: boundingBox.top}
|
||||
bottom: {x: boundingBox.left, y: boundingBox.bottom}
|
||||
|
||||
module.exports = PaneContainerElement = document.registerElement 'atom-pane-container', prototype: PaneContainerElement.prototype
|
||||
|
||||
@@ -222,25 +222,100 @@ class WorkspaceElement extends HTMLElement {
|
||||
this.model.getActivePane().activate()
|
||||
}
|
||||
|
||||
focusPaneViewAbove () { this.paneContainer.focusPaneViewAbove() }
|
||||
focusPaneViewAbove () { this.focusPaneViewInDirection('above') }
|
||||
|
||||
focusPaneViewBelow () { this.paneContainer.focusPaneViewBelow() }
|
||||
focusPaneViewBelow () { this.focusPaneViewInDirection('below') }
|
||||
|
||||
focusPaneViewOnLeft () { this.paneContainer.focusPaneViewOnLeft() }
|
||||
focusPaneViewOnLeft () { this.focusPaneViewInDirection('left') }
|
||||
|
||||
focusPaneViewOnRight () { this.paneContainer.focusPaneViewOnRight() }
|
||||
focusPaneViewOnRight () { this.focusPaneViewInDirection('right') }
|
||||
|
||||
moveActiveItemToPaneAbove (params) { this.paneContainer.moveActiveItemToPaneAbove(params) }
|
||||
focusPaneViewInDirection (direction, pane) {
|
||||
const activePane = this.model.getActivePane()
|
||||
const paneToFocus = this.nearestVisiblePaneInDirection(direction, activePane)
|
||||
paneToFocus && paneToFocus.focus()
|
||||
}
|
||||
|
||||
moveActiveItemToPaneBelow (params) { this.paneContainer.moveActiveItemToPaneBelow(params) }
|
||||
moveActiveItemToPaneAbove (params) {
|
||||
this.moveActiveItemToNearestPaneInDirection('above', params)
|
||||
}
|
||||
|
||||
moveActiveItemToPaneOnLeft (params) { this.paneContainer.moveActiveItemToPaneOnLeft(params) }
|
||||
moveActiveItemToPaneBelow (params) {
|
||||
this.moveActiveItemToNearestPaneInDirection('below', params)
|
||||
}
|
||||
|
||||
moveActiveItemToPaneOnRight (params) { this.paneContainer.moveActiveItemToPaneOnRight(params) }
|
||||
moveActiveItemToPaneOnLeft (params) {
|
||||
this.moveActiveItemToNearestPaneInDirection('left', params)
|
||||
}
|
||||
|
||||
moveActiveItemToPaneOnRight (params) {
|
||||
this.moveActiveItemToNearestPaneInDirection('right', params)
|
||||
}
|
||||
|
||||
moveActiveItemToNearestPaneInDirection (direction, params) {
|
||||
const activePane = this.model.getActivePane()
|
||||
const nearestPaneView = this.nearestVisiblePaneInDirection(direction, activePane)
|
||||
if (nearestPaneView == null) { return }
|
||||
if (params && params.keepOriginal) {
|
||||
activePane.getContainer().copyActiveItemToPane(nearestPaneView.getModel())
|
||||
} else {
|
||||
activePane.getContainer().moveActiveItemToPane(nearestPaneView.getModel())
|
||||
}
|
||||
nearestPaneView.focus()
|
||||
}
|
||||
|
||||
nearestVisiblePaneInDirection (direction, pane) {
|
||||
const paneContainerElement = pane.getContainer().getElement()
|
||||
return paneContainerElement.nearestPaneInDirection(direction, pane)
|
||||
const distance = function (pointA, pointB) {
|
||||
const x = pointB.x - pointA.x
|
||||
const y = pointB.y - pointA.y
|
||||
return Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2))
|
||||
}
|
||||
|
||||
const paneView = pane.getElement()
|
||||
const box = this.boundingBoxForPaneView(paneView)
|
||||
|
||||
const visiblePaneContainers = atom.workspace.getPaneContainers()
|
||||
.filter(container => {
|
||||
const isCenter = container === atom.workspace.getCenter()
|
||||
return isCenter || container.isVisible()
|
||||
})
|
||||
|
||||
const visiblePanes = _.flatten(visiblePaneContainers.map(container => container.getPanes()))
|
||||
|
||||
const paneViews = visiblePanes
|
||||
.map(otherPane => {
|
||||
return otherPane.getElement()
|
||||
}).filter(otherPaneView => {
|
||||
const otherBox = this.boundingBoxForPaneView(otherPaneView)
|
||||
switch (direction) {
|
||||
case 'left': return otherBox.right.x <= box.left.x
|
||||
case 'right': return otherBox.left.x >= box.right.x
|
||||
case 'above': return otherBox.bottom.y <= box.top.y
|
||||
case 'below': return otherBox.top.y >= box.bottom.y
|
||||
}
|
||||
}).sort((paneViewA, paneViewB) => {
|
||||
const boxA = this.boundingBoxForPaneView(paneViewA)
|
||||
const boxB = this.boundingBoxForPaneView(paneViewB)
|
||||
switch (direction) {
|
||||
case 'left': return distance(box.left, boxA.right) - distance(box.left, boxB.right)
|
||||
case 'right': return distance(box.right, boxA.left) - distance(box.right, boxB.left)
|
||||
case 'above': return distance(box.top, boxA.bottom) - distance(box.top, boxB.bottom)
|
||||
case 'below': return distance(box.bottom, boxA.top) - distance(box.bottom, boxB.top)
|
||||
}
|
||||
})
|
||||
|
||||
return paneViews[0]
|
||||
}
|
||||
|
||||
boundingBoxForPaneView (paneView) {
|
||||
const boundingBox = paneView.getBoundingClientRect()
|
||||
|
||||
return {
|
||||
left: {x: boundingBox.left, y: boundingBox.top},
|
||||
right: {x: boundingBox.right, y: boundingBox.top},
|
||||
top: {x: boundingBox.left, y: boundingBox.top},
|
||||
bottom: {x: boundingBox.left, y: boundingBox.bottom}
|
||||
}
|
||||
}
|
||||
|
||||
runPackageSpecs () {
|
||||
|
||||
Reference in New Issue
Block a user