Remove bindKey from views. Make FileFinder use atom.bindKeys

This commit is contained in:
Corey Johnson & Nathan Sobo
2012-01-11 12:15:31 -08:00
parent 1aa99c379f
commit 278ac6a9f2
6 changed files with 20 additions and 46 deletions

View File

@@ -32,29 +32,30 @@ describe 'FileFinder', ->
expect(finder.urlList.children().length).toBe 1
expect(finder.urlList.find('li:contains(atom/app.coffee)').length).toBe 1
describe "moveDown / moveUp", ->
describe "move-down / move-up events", ->
it "selects the next / previous url in the list", ->
expect(finder.find('li:eq(0)')).toHaveClass "selected"
expect(finder.find('li:eq(2)')).not.toHaveClass "selected"
finder.moveDown()
finder.moveDown()
finder.trigger 'move-down'
finder.trigger 'move-down'
expect(finder.find('li:eq(0)')).not.toHaveClass "selected"
expect(finder.find('li:eq(2)')).toHaveClass "selected"
finder.moveUp()
finder.trigger 'move-up'
expect(finder.find('li:eq(0)')).not.toHaveClass "selected"
expect(finder.find('li:eq(1)')).toHaveClass "selected"
expect(finder.find('li:eq(2)')).not.toHaveClass "selected"
it "does not fall off the end or begining of the list", ->
expect(finder.find('li:first')).toHaveClass "selected"
finder.moveUp()
finder.trigger 'move-up'
expect(finder.find('li:first')).toHaveClass "selected"
for i in [1..urls.length+10]
finder.moveDown()
finder.trigger 'move-down'
expect(finder.find('li:last')).toHaveClass "selected"
@@ -67,7 +68,7 @@ describe 'FileFinder', ->
it "when a file is selected Editor.open is called", ->
spyOn(finder, 'remove')
finder.moveDown()
finder.select()
finder.trigger 'select'
expect(selectedCallback).toHaveBeenCalledWith(urls[1])
expect(finder.remove).toHaveBeenCalled()
@@ -75,7 +76,7 @@ describe 'FileFinder', ->
spyOn(atom, 'open')
finder.input.val('this-will-match-nothing-hopefully')
finder.populateUrlList()
finder.select()
finder.trigger 'select'
expect(atom.open).not.toHaveBeenCalled()
describe "findMatches(queryString)", ->

View File

@@ -79,7 +79,7 @@ describe "RootView", ->
waitsForPromise -> rootView.resultOfTrigger 'toggle-file-finder'
runs ->
firstLi = rootView.fileFinder.find('li:first')
rootView.fileFinder.select()
rootView.fileFinder.trigger 'select'
expect(rootView.editor.buffer.url).toBe(project.url + firstLi.text())
describe "global keymap wiring", ->

View File

@@ -89,26 +89,3 @@ describe "Template", ->
expect(view.subview.view()).toBe view.subview
expect(view.subview.header.view()).toBe view.subview
describe "$.fn.bindKey", ->
describe "when passed a key pattern and a method name", ->
it "calls the named method on the parent view when a keydown event matches the pattern", ->
view.someMethod = jasmine.createSpy('someMethod')
view.li1.bindKey 'ctrl+m', 'someMethod'
view.li1.trigger window.keydownEvent('meta+z')
expect(view.someMethod).not.toHaveBeenCalled()
view.li1.trigger window.keydownEvent('ctrl+m')
expect(view.someMethod).toHaveBeenCalled()
describe "when passed a key pattern and a function", ->
it "calls the given function when a keydown event matches the pattern", ->
action = jasmine.createSpy('someMethod')
view.li1.bindKey 'ctrl+m', action
view.li1.trigger window.keydownEvent('meta+z')
expect(action).not.toHaveBeenCalled()
view.li1.trigger window.keydownEvent('ctrl+m')
expect(action).toHaveBeenCalled()

View File

@@ -10,7 +10,7 @@ class App
constructor: ->
@native = new Native
@globalKeymap = new GlobalKeymap
$(document).on 'keydown', (e) => console.log e; @globalKeymap.handleKeyEvent(e)
$(document).on 'keydown', (e) => @globalKeymap.handleKeyEvent(e)
bindKeys: (selector, bindings) ->
@globalKeymap.bindKeys(selector, bindings)

View File

@@ -5,8 +5,8 @@ stringScore = require 'stringscore'
module.exports =
class FileFinder extends Template
content: ->
@link rel: 'stylesheet', href: "#{require.resolve('file-finder.css')}?#{(new Date).getTime()}"
@div class: 'file-finder', =>
@link rel: 'stylesheet', href: "#{require.resolve('file-finder.css')}?#{(new Date).getTime()}"
@ol outlet: 'urlList'
@input outlet: 'input', input: 'populateUrlList'
@@ -18,9 +18,14 @@ class FileFinder extends Template
@maxResults = 10
@populateUrlList()
@bindKey 'up', 'moveUp'
@bindKey 'down', 'moveDown'
@bindKey 'enter', 'select'
atom.bindKeys ".file-finder",
'up': 'move-up'
'down': 'move-down'
'enter': 'select'
@on 'move-up', => @moveUp()
@on 'move-down', => @moveDown()
@on 'select', => @select()
populateUrlList: ->
@urlList.empty()

View File

@@ -51,12 +51,3 @@ class Template
$.fn.view = ->
this.data('view')
$.fn.bindKey = (pattern, action) ->
@on 'keydown', (event) =>
bindingSet = new (require('binding-set'))("*", {})
if bindingSet.eventMatchesPattern(event, pattern)
if _.isString(action)
this.view()[action]()
else
action()