Select path when collapsed via command

This commit is contained in:
Kevin Sawicki
2013-02-13 21:57:42 -08:00
parent 20d7956cc1
commit 1cc6429dc7
2 changed files with 16 additions and 7 deletions

View File

@@ -15,16 +15,20 @@ class PathView extends View
for operation in operations
@subview "operation#{operation.index}", new OperationView({operation, previewList})
initialize: ({previewList}) ->
initialize: ({@previewList}) ->
@on 'mousedown', @onPathSelected
previewList.command 'command-panel:collapse-result', =>
@collapse(true) if @isSelected()
previewList.command 'command-panel:expand-result', =>
@previewList.command 'command-panel:collapse-result', =>
@collapse(true, true) if @isSelected()
@previewList.command 'command-panel:expand-result', =>
@expand(true) if @isSelected()
isSelected: ->
@hasClass('selected') or @find('.selected').length
setSelected: ->
@previewList.find('.selected').removeClass('selected')
@addClass('selected')
onPathSelected: (event) =>
e = $(event.target)
e = e.parent() if e.parent().hasClass 'path'
@@ -43,9 +47,12 @@ class PathView extends View
@matches.show()
@removeClass 'is-collapsed'
collapse: (animate=false) ->
collapse: (animate=false, select=false) ->
if animate
@matches.hide 100, => @addClass 'is-collapsed'
@matches.hide 100, =>
@addClass 'is-collapsed'
@setSelected() if select
else
@matches.hide()
@addClass 'is-collapsed'
@setSelected() if select

View File

@@ -480,10 +480,12 @@ describe "CommandPanel", ->
expect(previewList.find('li.path:first-child ul.matches')).toBeVisible()
describe "when command-panel:collapse-result and command-panel:expand-result are triggered", ->
it "collapses and expands the path of the selection", ->
it "collapses and selects the path, and then expands the selected path", ->
rootView.attachToDom()
expect(previewList.find('li.path:first-child ul.matches')).toBeVisible()
previewList.trigger 'command-panel:collapse-result'
expect(previewList.find('li.path:first-child ul.matches')).toBeHidden()
expect(previewList.find('li.path:first-child')).toHaveClass 'selected'
previewList.trigger 'command-panel:expand-result'
expect(previewList.find('li.path:first-child ul.matches')).toBeVisible()
expect(previewList.find('li.path:first-child')).toHaveClass 'selected'