Right arrow collapses directories in TreeView

This commit is contained in:
Nathan Sobo
2012-04-24 18:08:29 -06:00
parent 48069dc898
commit 7e7d37859f
3 changed files with 44 additions and 1 deletions

View File

@@ -193,3 +193,39 @@ describe "TreeView", ->
it "does nothing", ->
rootDirectoryView.find('.file').click()
treeView.trigger 'tree-view:expand-directory'
describe "tree-view:collapse-directory", ->
subdir = null
beforeEach ->
subdir = rootDirectoryView.find('> .entries > .directory').eq(0).view()
subdir.expand()
describe "when an expanded directory is selected", ->
it "collapses the selected directory", ->
expect(subdir).toHaveClass 'expanded'
subdir.click()
treeView.trigger 'tree-view:collapse-directory'
expect(subdir).not.toHaveClass 'expanded'
expect(rootDirectoryView).toHaveClass 'expanded'
describe "when a collapsed directory is selected", ->
it "collapses and selects the selected directory's parent directory", ->
subdir.find('.directory').click()
treeView.trigger 'tree-view:collapse-directory'
expect(subdir).not.toHaveClass 'expanded'
expect(subdir).toHaveClass 'selected'
expect(rootDirectoryView).toHaveClass 'expanded'
describe "when a file is selected", ->
it "collapses and selects the selected file's parent directory", ->
subdir.find('.file').click()
treeView.trigger 'tree-view:collapse-directory'
expect(subdir).not.toHaveClass 'expanded'
expect(subdir).toHaveClass 'selected'
expect(rootDirectoryView).toHaveClass 'expanded'

View File

@@ -1,4 +1,4 @@
window.keymap.bindKeys '.tree-view'
'right': 'tree-view:expand-directory'
'left': 'tree-view:contract-directory'
'left': 'tree-view:collapse-directory'

View File

@@ -22,6 +22,7 @@ class TreeView extends View
@on 'move-up', => @moveUp()
@on 'move-down', => @moveDown()
@on 'tree-view:expand-directory', => @expandDirectory()
@on 'tree-view:collapse-directory', => @collapseDirectory()
@rootView.on 'active-editor-path-change', => @selectActiveFile()
selectActiveFile: ->
@@ -50,6 +51,12 @@ class TreeView extends View
selectedEntry = @selectedEntry()
selectedEntry.view().expand() if selectedEntry.is('.directory')
collapseDirectory: ->
selectedEntry = @selectedEntry()
directory = selectedEntry.closest('.expanded.directory').view()
directory.collapse()
@selectEntry(directory)
selectedEntry: ->
@find('.selected')