Skip to content

Commit 6b118a8

Browse files
committed
Add convenience commands to copy/move active item between panes
Give focus to destination pane and set the copied/moved item as active
1 parent 500afb0 commit 6b118a8

4 files changed

+46
-0
lines changed

src/pane-container-element.coffee

+21
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,27 @@ class PaneContainerElement extends HTMLElement
3636
focusPaneViewOnRight: ->
3737
@nearestPaneInDirection('right')?.focus()
3838

39+
moveActiveItemToPaneAbove: (params) ->
40+
@moveActiveItemToNearestPaneInDirection('above', params)
41+
42+
moveActiveItemToPaneBelow: (params) ->
43+
@moveActiveItemToNearestPaneInDirection('below', params)
44+
45+
moveActiveItemToPaneOnLeft: (params) ->
46+
@moveActiveItemToNearestPaneInDirection('left', params)
47+
48+
moveActiveItemToPaneOnRight: (params) ->
49+
@moveActiveItemToNearestPaneInDirection('right', params)
50+
51+
moveActiveItemToNearestPaneInDirection: (direction, params) ->
52+
destPane = @nearestPaneInDirection(direction)?.getModel()
53+
return unless destPane?
54+
if params?.keepOriginal
55+
@model.copyActiveItemToPane(destPane)
56+
else
57+
@model.moveActiveItemToPane(destPane)
58+
destPane.focus()
59+
3960
nearestPaneInDirection: (direction) ->
4061
distance = (pointA, pointB) ->
4162
x = pointB.x - pointA.x

src/pane-container.coffee

+9
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,15 @@ class PaneContainer extends Model
164164
else
165165
false
166166

167+
moveActiveItemToPane: (destPane) ->
168+
item = @activePane.getActiveItem()
169+
@activePane.moveItemToPane(item, destPane)
170+
destPane.setActiveItem(item)
171+
172+
copyActiveItemToPane: (destPane) ->
173+
item = @activePane.copyActiveItem()
174+
destPane.activateItem(item)
175+
167176
destroyEmptyPanes: ->
168177
pane.destroy() for pane in @getPanes() when pane.items.length is 0
169178
return

src/register-default-commands.coffee

+8
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,14 @@ module.exports = ({commandRegistry, commandInstaller, config}) ->
5050
'window:focus-pane-below': -> @focusPaneViewBelow()
5151
'window:focus-pane-on-left': -> @focusPaneViewOnLeft()
5252
'window:focus-pane-on-right': -> @focusPaneViewOnRight()
53+
'window:move-active-item-to-pane-above': -> @moveActiveItemToPaneAbove()
54+
'window:move-active-item-to-pane-below': -> @moveActiveItemToPaneBelow()
55+
'window:move-active-item-to-pane-on-left': -> @moveActiveItemToPaneOnLeft()
56+
'window:move-active-item-to-pane-on-right': -> @moveActiveItemToPaneOnRight()
57+
'window:copy-active-item-to-pane-above': -> @moveActiveItemToPaneAbove(keepOriginal: true)
58+
'window:copy-active-item-to-pane-below': -> @moveActiveItemToPaneBelow(keepOriginal: true)
59+
'window:copy-active-item-to-pane-on-left': -> @moveActiveItemToPaneOnLeft(keepOriginal: true)
60+
'window:copy-active-item-to-pane-on-right': -> @moveActiveItemToPaneOnRight(keepOriginal: true)
5361
'window:save-all': -> @getModel().saveAll()
5462
'window:toggle-invisibles': -> config.set("editor.showInvisibles", not config.get("editor.showInvisibles"))
5563
'window:log-deprecation-warnings': -> Grim.logDeprecations()

src/workspace-element.coffee

+8
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,14 @@ class WorkspaceElement extends HTMLElement
104104

105105
focusPaneViewOnRight: -> @paneContainer.focusPaneViewOnRight()
106106

107+
moveActiveItemToPaneAbove: (params) -> @paneContainer.moveActiveItemToPaneAbove(params)
108+
109+
moveActiveItemToPaneBelow: (params) -> @paneContainer.moveActiveItemToPaneBelow(params)
110+
111+
moveActiveItemToPaneOnLeft: (params) -> @paneContainer.moveActiveItemToPaneOnLeft(params)
112+
113+
moveActiveItemToPaneOnRight: (params) -> @paneContainer.moveActiveItemToPaneOnRight(params)
114+
107115
runPackageSpecs: ->
108116
if activePath = @workspace.getActivePaneItem()?.getPath?()
109117
[projectPath] = @project.relativizePath(activePath)

0 commit comments

Comments
 (0)