autoscroll to results in command panel preview list

This commit is contained in:
Corey Johnson
2012-12-03 10:23:28 -08:00
parent 5b143d4b93
commit 5d99824deb
3 changed files with 12 additions and 3 deletions

View File

@@ -935,6 +935,9 @@ class Editor extends View
getLastVisibleScreenRow: ->
Math.max(0, Math.ceil((@scrollTop() + @scrollView.height()) / @lineHeight) - 1)
isScreenRowVisible: (row) ->
@getFirstVisibleScreenRow() <= row <= @getLastVisibleScreenRow()
handleScreenLinesChange: (change) ->
@pendingChanges.push(change)
@requestDisplayUpdate()

View File

@@ -374,7 +374,7 @@ describe "CommandPanel", ->
beforeEach ->
previewList = commandPanel.previewList
rootView.trigger 'command-panel:toggle'
waitsForPromise -> commandPanel.execute('X x/a+/')
waitsForPromise -> commandPanel.execute('X x/apply/')
describe "when move-down and move-up are triggered on the preview list", ->
it "selects the next/previous operation (if there is one), and scrolls the list if needed", ->
@@ -408,7 +408,10 @@ describe "CommandPanel", ->
_.times previewList.getOperations().length, -> previewList.trigger 'core:move-up'
describe "when core:confirm is triggered on the preview list", ->
it "opens the operation's buffer, selects the search result, and focuses the active editor", ->
it "opens the operation's buffer, selects and scrolls to the search result, and focuses the active editor", ->
rootView.height(200)
rootView.attachToDom()
spyOn(rootView, 'focus')
executeHandler = jasmine.createSpy('executeHandler')
commandPanel.on 'core:confirm', executeHandler
@@ -421,6 +424,9 @@ describe "CommandPanel", ->
editSession = rootView.getActiveEditSession()
expect(editSession.buffer.getPath()).toBe project.resolve(operation.getPath())
expect(editSession.getSelectedBufferRange()).toEqual operation.getBufferRange()
expect(editSession.getSelectedBufferRange()).toEqual operation.getBufferRange()
console.log editor.getCursorScreenRow(), editor.getFirstVisibleScreenRow(), editor.getLastVisibleScreenRow()
expect(editor.isScreenRowVisible(editor.getCursorScreenRow())).toBeTruthy()
expect(rootView.focus).toHaveBeenCalled()
expect(executeHandler).not.toHaveBeenCalled()

View File

@@ -61,7 +61,7 @@ class PreviewList extends ScrollView
operation = @getSelectedOperation()
editSession = @rootView.open(operation.getPath())
bufferRange = operation.execute(editSession)
editSession.setSelectedBufferRange(bufferRange) if bufferRange
editSession.setSelectedBufferRange(bufferRange, autoscroll: true) if bufferRange
@rootView.focus()
false