mirror of
https://github.com/atom/atom.git
synced 2026-04-28 03:01:47 -04:00
Update selected operation on move-to-top/move-to-bottom
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user