diff --git a/src/packages/command-panel/lib/path-view.coffee b/src/packages/command-panel/lib/path-view.coffee index a22a02267..2d64de407 100644 --- a/src/packages/command-panel/lib/path-view.coffee +++ b/src/packages/command-panel/lib/path-view.coffee @@ -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 diff --git a/src/packages/command-panel/spec/command-panel-spec.coffee b/src/packages/command-panel/spec/command-panel-spec.coffee index dc4250ce3..52796cb32 100644 --- a/src/packages/command-panel/spec/command-panel-spec.coffee +++ b/src/packages/command-panel/spec/command-panel-spec.coffee @@ -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'