Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

Make 'Split <direction>' context menu option work with directories #1190

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 19 additions & 6 deletions lib/tree-view.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -463,12 +463,25 @@ class TreeView
return unless selectedEntry?

pane = atom.workspace.getCenter().getActivePane()
if pane and selectedEntry.classList.contains('file')
if atom.workspace.getCenter().getActivePaneItem()
split = pane.split orientation, side
atom.workspace.openURIInPane selectedEntry.getPath(), split
else
@openSelectedEntry yes
if pane
if selectedEntry.classList.contains('file')
if atom.workspace.getCenter().getActivePaneItem()
split = pane.split orientation, side
atom.workspace.openURIInPane selectedEntry.getPath(), split
else
@openSelectedEntry yes
else if selectedEntry.classList.contains('directory')
if atom.workspace.getCenter().getActivePaneItem()
split = pane.split orientation, side
selectedEntry.directory.entries.forEach((subEntry) ->
unless subEntry instanceof Directory
atom.workspace.openURIInPane subEntry.realPath, split
)
else
selectedEntry.directory.entries.forEach((subEntry) ->
unless subEntry instanceof Directory
atom.workspace.openURIInPane subEntry.realPath, pane
)

openSelectedEntryRight: ->
@openSelectedEntrySplit 'horizontal', 'after'
Expand Down
2 changes: 1 addition & 1 deletion menus/tree-view.cson
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
{'label': 'Open In New Window', 'command': 'tree-view:open-in-new-window'}
]

'.tree-view .full-menu [is="tree-view-file"]': [
'.tree-view .full-menu [is^="tree-view"]': [
{'label': 'Split Up', 'command': 'tree-view:open-selected-entry-up'}
{'label': 'Split Down', 'command': 'tree-view:open-selected-entry-down'}
{'label': 'Split Left', 'command': 'tree-view:open-selected-entry-left'}
Expand Down
23 changes: 23 additions & 0 deletions spec/tree-view-package-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -1291,6 +1291,29 @@ describe "TreeView", ->
atom.commands.dispatch(treeView.element, 'tree-view:expand-item')
expect(atom.workspace.getCenter().getActivePaneItem()).toBeUndefined()

describe "opening directory in a split pane", ->
beforeEach ->
jasmine.attachToDOM(workspaceElement)
treeView.selectEntryForPath path1
atom.commands.dispatch(treeView.element, 'tree-view:open-selected-entry-right')
pane = atom.workspace.getCenter().getPanes()[0]
waitsFor ->
pane.getItems().length >= 2

it "opens a single pane", ->
expect(atom.workspace.getCenter().getPanes().length).toBe 1

it "opens the directory files in pane 0 and focuses it", ->
pane = atom.workspace.getCenter().getPanes()[0]
itemPaths = pane.getItems().map (item) -> item.getPath()

expect(atom.views.getView(pane)).toHaveFocus()
expect(itemPaths.length).toBe(2)

expect(itemPaths).toContain atom.project.getDirectories()[0].resolve('tree-view.js')
expect(itemPaths).toContain atom.project.getDirectories()[0].resolve('tree-view.txt')


describe "opening in existing split panes", ->
beforeEach ->
jasmine.attachToDOM(workspaceElement)
Expand Down