Update selected operation on move-to-top/move-to-bottom

This commit is contained in:
Kevin Sawicki
2013-01-04 13:31:14 -08:00
parent 8591c86733
commit 8e1ae24eb4
2 changed files with 33 additions and 5 deletions

View File

@@ -429,6 +429,21 @@ describe "CommandPanel", ->
expect(previewList.find('li.operation:eq(0)')).toHaveClass 'selected'
expect(commandPanel.miniEditor.getText()).toBe 'command'
describe "when move-to-top and move-to-bottom are triggered on the preview list", ->
it "selects the first/last operation", ->
rootView.attachToDom()
expect(previewList.getOperations().length).toBeGreaterThan 0
expect(previewList.find('li.operation:eq(0)')).toHaveClass 'selected'
expect(previewList.getSelectedOperation()).toBe previewList.getOperations()[0]
previewList.trigger 'core:move-to-bottom'
expect(previewList.find('li.operation:last')).toHaveClass 'selected'
expect(previewList.getSelectedOperation()).toBe _.last(previewList.getOperations())
previewList.trigger 'core:move-to-top'
expect(previewList.find('li.operation:eq(0)')).toHaveClass 'selected'
expect(previewList.getSelectedOperation()).toBe previewList.getOperations()[0]
describe "when core:confirm is triggered on the preview list", ->
it "opens the operation's buffer, selects and scrolls to the search result, and focuses the active editor", ->
rootView.height(200)

View File

@@ -67,16 +67,19 @@ class PreviewList extends ScrollView
else
@setSelectedOperationIndex(@selectedOperationIndex - 1)
setSelectedOperationIndex: (index) ->
setSelectedOperationIndex: (index, scrollToOperation=true) ->
index = Math.max(0, index)
index = Math.min(@operations.length - 1, index)
@children(".selected").removeClass('selected')
element = @children("li.operation:eq(#{index})")
element.addClass('selected')
if index is 0
@scrollToTop()
else
@scrollToElement(element)
if scrollToOperation
if index is 0
@scrollToTop()
else
@scrollToElement(element)
@selectedOperationIndex = index
executeSelectedOperation: ->
@@ -105,3 +108,13 @@ class PreviewList extends ScrollView
@scrollBottom(bottom)
if top < @scrollTop()
@scrollTop(top)
scrollToBottom: ->
super()
@setSelectedOperationIndex(Infinity, false)
scrollToTop: ->
super()
@setSelectedOperationIndex(0, false)