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

Commit

Permalink
Add recursive collapse tests and refactor collapseDirectory
Browse files Browse the repository at this point in the history
  • Loading branch information
darkowlzz committed Oct 2, 2017
1 parent afcdebe commit b8c4b98
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 13 deletions.
1 change: 0 additions & 1 deletion keymaps/tree-view.cson
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@
'l': 'tree-view:expand-item'
'left': 'tree-view:collapse-directory'
'ctrl-[': 'tree-view:collapse-directory'
'ctrl-r': 'tree-view:collapse-all'
'alt-ctrl-]': 'tree-view:recursive-expand-directory'
'alt-right': 'tree-view:recursive-expand-directory'
'alt-ctrl-[': 'tree-view:recursive-collapse-directory'
Expand Down
11 changes: 5 additions & 6 deletions lib/tree-view.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ class TreeView
'tree-view:recursive-expand-directory': => @expandDirectory(true)
'tree-view:collapse-directory': => @collapseDirectory()
'tree-view:recursive-collapse-directory': => @collapseDirectory(true)
'tree-view:collapse-all': => @collapseDirectory(true, true)
'tree-view:open-selected-entry': => @openSelectedEntry()
'tree-view:open-selected-entry-right': => @openSelectedEntryRight()
'tree-view:open-selected-entry-left': => @openSelectedEntryLeft()
Expand All @@ -197,7 +198,6 @@ class TreeView
'tree-view:toggle-vcs-ignored-files': -> toggleConfig 'tree-view.hideVcsIgnoredFiles'
'tree-view:toggle-ignored-names': -> toggleConfig 'tree-view.hideIgnoredNames'
'tree-view:remove-project-folder': (e) => @removeProjectFolder(e)
'tree-view:collapse-all': => @collapseAll()

[0..8].forEach (index) =>
atom.commands.add @element, "tree-view:open-selected-entry-in-pane-#{index + 1}", =>
Expand All @@ -219,9 +219,6 @@ class TreeView
@disposables.add atom.config.onDidChange 'tree-view.squashDirectoryNames', =>
@updateRoots()

collapseAll: ->
root.collapse(true) for root in @roots

toggle: ->
atom.workspace.toggle(this)

Expand Down Expand Up @@ -440,11 +437,13 @@ class TreeView
else
directory.expand(isRecursive)

collapseDirectory: (isRecursive=false) ->
collapseDirectory: (isRecursive=false, allDirectories=false) ->
selectedEntry = @selectedEntry()
return unless selectedEntry?

if directory = selectedEntry.closest('.expanded.directory')
if allDirectories
root.collapse(true) for root in @roots
else if directory = $(selectedEntry).closest('.expanded.directory')[0]
directory.collapse(isRecursive)
@selectEntry(directory)

Expand Down
23 changes: 17 additions & 6 deletions spec/tree-view-package-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -1155,14 +1155,25 @@ describe "TreeView", ->
expect(treeView.roots[0]).toHaveClass 'expanded'

describe "tree-view:collapse-all", ->
it "collapses all the project directories", ->
expect(treeView.roots[0]).toHaveClass 'expanded'
expect(treeView.roots[1]).toHaveClass 'expanded'
expandAll = ->
for root in treeView.roots
root.expand(true)
children = $(root).find('.directory')
children.each (index, child) ->
expect(child).toHaveClass 'expanded'
expect(root).toHaveClass 'expanded'

atom.commands.dispatch(treeView.element, 'tree-view:collapse-all')
checkAllCollapsed = ->
for root in treeView.roots
children = $(root).find('.directory')
children.each (index, child) ->
expect(child).not.toHaveClass 'expanded'
expect(root).not.toHaveClass 'expanded'

expect(treeView.roots[0]).not.toHaveClass 'expanded'
expect(treeView.roots[1]).not.toHaveClass 'expanded'
it "collapses all the project directories recursively", ->
expandAll()
atom.commands.dispatch(treeView.element, 'tree-view:collapse-all')
checkAllCollapsed()

describe "tree-view:open-selected-entry", ->
describe "when a file is selected", ->
Expand Down

0 comments on commit b8c4b98

Please sign in to comment.