mirror of
https://github.com/atom/atom.git
synced 2026-04-28 03:01:47 -04:00
Add $.fn.bindKey, which works on any jquery-wrapped element.
If given a string as an action, it attempts to call a method by that name on the element's view object. If given a function, it calls it directly.
This commit is contained in:
@@ -18,11 +18,6 @@ class FileFinder extends Template
|
||||
@bindKey 'up', 'moveUp'
|
||||
@bindKey 'down', 'moveDown'
|
||||
|
||||
bindKey: (pattern, methodName) ->
|
||||
@on 'keydown', (event) =>
|
||||
if window.keyEventMatchesPattern(event, pattern)
|
||||
this[methodName]()
|
||||
|
||||
populateUrlList: ->
|
||||
@urlList.empty()
|
||||
for url in @findMatches(@input.val())
|
||||
|
||||
@@ -51,3 +51,11 @@ class Template
|
||||
$.fn.view = ->
|
||||
this.data('view')
|
||||
|
||||
$.fn.bindKey = (pattern, action) ->
|
||||
@on 'keydown', (event) =>
|
||||
if window.keyEventMatchesPattern(event, pattern)
|
||||
if _.isString(action)
|
||||
this.view()[action]()
|
||||
else
|
||||
action()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user