Pressing 'enter' on a global search operation selects it in the active editor

This commit is contained in:
Nathan Sobo
2012-07-23 18:16:37 -06:00
parent 8f0c8633f8
commit c3c4e07a3f
4 changed files with 30 additions and 6 deletions

View File

@@ -3,12 +3,13 @@ CommandPanel = require 'command-panel'
_ = require 'underscore'
describe "CommandPanel", ->
[rootView, editor, buffer, commandPanel] = []
[rootView, editor, buffer, commandPanel, project] = []
beforeEach ->
rootView = new RootView
rootView.open(require.resolve 'fixtures/sample.js')
rootView.enableKeymap()
project = rootView.project
editor = rootView.getActiveEditor()
buffer = editor.activeEditSession.buffer
commandPanel = requireExtension('command-panel')
@@ -271,7 +272,7 @@ describe "CommandPanel", ->
commandPanel.miniEditor.trigger 'move-down'
expect(commandPanel.miniEditor.getText()).toBe ''
describe "when the preview list is focused", ->
describe "when the preview list is focused with search operations", ->
previewList = null
beforeEach ->
@@ -311,3 +312,19 @@ describe "CommandPanel", ->
_.times previewList.getOperations().length, -> previewList.trigger 'move-up'
console.log previewList.find('li:first').position().top
describe "when command-panel:execute is triggered on the preview list", ->
it "opens a new editor with the operation's buffer and selects the search result", ->
executeHandler = jasmine.createSpy('executeHandler')
commandPanel.on 'command-panel:execute', executeHandler
_.times 4, -> previewList.trigger 'move-down'
operation = previewList.getSelectedOperation()
previewList.trigger 'command-panel:execute'
editSession = rootView.getActiveEditSession()
expect(editSession.buffer.getPath()).toBe project.resolve(operation.getPath())
expect(editSession.getSelectedBufferRange()).toEqual operation.getBufferRange()
expect(executeHandler).not.toHaveBeenCalled()

View File

@@ -29,9 +29,9 @@ class CommandPanel extends View
commandPanel.attach(state.text) if state.visible
commandPanel
@content: ->
@content: (rootView) ->
@div class: 'command-panel', =>
@subview 'previewList', new PreviewList()
@subview 'previewList', new PreviewList(rootView)
@div class: 'prompt-and-editor', =>
@div ':', class: 'prompt', outlet: 'prompt'
@subview 'miniEditor', new Editor(mini: true)

View File

@@ -4,7 +4,7 @@ window.keymap.bindKeys '*'
'meta-:': 'command-panel:toggle'
'meta-F': 'command-panel:find-in-project'
window.keymap.bindKeys '.command-panel .editor input',
window.keymap.bindKeys '.command-panel, .command-panel .editor input',
'meta-w': 'command-panel:toggle'
escape: 'command-panel:unfocus'
enter: 'command-panel:execute'

View File

@@ -8,9 +8,10 @@ class PreviewList extends View
selectedOperationIndex: 0
operations: null
initialize: ->
initialize: (@rootView) ->
@on 'move-down', => @selectNextOperation()
@on 'move-up', => @selectPreviousOperation()
@on 'command-panel:execute', => @executeSelectedOperation()
hasOperations: -> @operations?
@@ -45,6 +46,12 @@ class PreviewList extends View
@scrollToElement(element)
@selectedOperationIndex = index
executeSelectedOperation: ->
operation = @getSelectedOperation()
editSession = @rootView.open(operation.getPath())
operation.execute(editSession)
false
getOperations: ->
new Array(@operations...)