Down-arrow selects the next entry in the file browser, correctly traversing the file hierarchy

This commit is contained in:
Nathan Sobo
2012-04-24 13:58:37 -06:00
parent fd900d5760
commit 35b68514ed
2 changed files with 27 additions and 4 deletions

View File

@@ -2,7 +2,7 @@ TreeView = require 'tree-view'
RootView = require 'root-view'
Directory = require 'directory'
describe "TreeView", ->
fdescribe "TreeView", ->
[rootView, project, treeView, rootDirectoryView, sampleJs, sampleTxt] = []
beforeEach ->
@@ -120,9 +120,29 @@ describe "TreeView", ->
describe "if an expanded directory is selected", ->
it "selects the first entry of the directory", ->
subdir = rootDirectoryView.find('.directory:eq(1)').view()
subdir.expand()
subdir.click()
treeView.trigger 'move-down'
expect(subdir.entries.find('.entry:first')).toHaveClass 'selected'
describe "if the last entry of an expanded directory is selected", ->
it "selects the entry after its parent directory", ->
subdir1 = rootDirectoryView.find('.directory:eq(1)').view()
subdir1.expand()
subdir1.entries.find('.entry:last').click()
treeView.trigger 'move-down'
expect(rootDirectoryView.find('.entries > .entry:eq(2)')).toHaveClass 'selected'
describe "if the last entry of the last directory is selected", ->
it "does not change the selection", ->
lastEntry = rootDirectoryView.find('> .entries .entry:last')
lastEntry.click()
treeView.trigger 'move-down'
expect(lastEntry).toHaveClass 'selected'

View File

@@ -28,9 +28,11 @@ class TreeView extends View
moveDown: ->
selectedEntry = @selectedEntry()
if selectedEntry.length
@selectEntry(selectedEntry.next())
if selectedEntry[0]
if selectedEntry.is('.expanded.directory')
return if @selectEntry(selectedEntry.find('.entry:first'))
return if @selectEntry(selectedEntry.next())
return if @selectEntry(selectedEntry.closest('.directory').next())
else
@selectEntry(@root)
@@ -38,6 +40,7 @@ class TreeView extends View
@find('.selected')
selectEntry: (entry) ->
return false unless entry[0]
@find('.selected').removeClass('selected')
entry.addClass('selected')