mirror of
https://github.com/atom/atom.git
synced 2026-04-28 03:01:47 -04:00
Merge pull request #1484 from atom/directional-pane-navigation
Add commands to move directionally between panes
This commit is contained in:
@@ -98,3 +98,50 @@ class PaneContainerView extends View
|
||||
|
||||
focusPreviousPane: ->
|
||||
@model.activatePreviousPane()
|
||||
|
||||
focusPaneAbove: ->
|
||||
@nearestPaneInDirection('above')?.focus()
|
||||
|
||||
focusPaneBelow: ->
|
||||
@nearestPaneInDirection('below')?.focus()
|
||||
|
||||
focusPaneOnLeft: ->
|
||||
@nearestPaneInDirection('left')?.focus()
|
||||
|
||||
focusPaneOnRight: ->
|
||||
@nearestPaneInDirection('right')?.focus()
|
||||
|
||||
nearestPaneInDirection: (direction) ->
|
||||
distance = (pointA, pointB) ->
|
||||
x = pointB.x - pointA.x
|
||||
y = pointB.y - pointA.y
|
||||
Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2))
|
||||
|
||||
pane = @getActivePane()
|
||||
box = @boundingBoxForPane(pane)
|
||||
panes = @getPanes()
|
||||
.filter (otherPane) =>
|
||||
otherBox = @boundingBoxForPane(otherPane)
|
||||
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 (paneA, paneB) =>
|
||||
boxA = @boundingBoxForPane(paneA)
|
||||
boxB = @boundingBoxForPane(paneB)
|
||||
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)
|
||||
|
||||
panes[0]
|
||||
|
||||
boundingBoxForPane: (pane) ->
|
||||
boundingBox = pane[0].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}
|
||||
|
||||
@@ -121,6 +121,10 @@ class WorkspaceView extends View
|
||||
|
||||
@command 'window:focus-next-pane', => @focusNextPane()
|
||||
@command 'window:focus-previous-pane', => @focusPreviousPane()
|
||||
@command 'window:focus-pane-above', => @focusPaneAbove()
|
||||
@command 'window:focus-pane-below', => @focusPaneBelow()
|
||||
@command 'window:focus-pane-on-left', => @focusPaneOnLeft()
|
||||
@command 'window:focus-pane-on-right', => @focusPaneOnRight()
|
||||
@command 'window:save-all', => @saveAll()
|
||||
@command 'window:toggle-invisibles', =>
|
||||
atom.config.toggle("editor.showInvisibles")
|
||||
@@ -245,6 +249,18 @@ class WorkspaceView extends View
|
||||
# Public: Focuses the next pane by id.
|
||||
focusNextPane: -> @model.activateNextPane()
|
||||
|
||||
# Public: Focuses the pane directly above the active pane.
|
||||
focusPaneAbove: -> @panes.focusPaneAbove()
|
||||
|
||||
# Public: Focuses the pane directly below the active pane.
|
||||
focusPaneBelow: -> @panes.focusPaneBelow()
|
||||
|
||||
# Public: Focuses the pane directly to the left of the active pane.
|
||||
focusPaneOnLeft: -> @panes.focusPaneOnLeft()
|
||||
|
||||
# Public: Focuses the pane directly to the right of the active pane.
|
||||
focusPaneOnRight: -> @panes.focusPaneOnRight()
|
||||
|
||||
# Public:
|
||||
#
|
||||
# FIXME: Difference between active and focused pane?
|
||||
|
||||
Reference in New Issue
Block a user