mirror of
https://github.com/atom/atom.git
synced 2026-04-28 03:01:47 -04:00
Bound up / down keys to moveUp / moveDown in fileFinder
This commit is contained in:
@@ -6,15 +6,22 @@ module.exports =
|
||||
class FileFinder extends Template
|
||||
content: ->
|
||||
@link rel: 'stylesheet', href: "#{require.resolve('file-finder.css')}?#{(new Date).getTime()}"
|
||||
@div keydown: 'handleKeydown', class: 'file-finder', =>
|
||||
@div class: 'file-finder', =>
|
||||
@ol outlet: 'urlList'
|
||||
@input outlet: 'input', keyup: 'populateUrlList'
|
||||
@input outlet: 'input', input: 'populateUrlList'
|
||||
|
||||
viewProperties:
|
||||
urls: null
|
||||
|
||||
initialize: ({@urls}) ->
|
||||
@populateUrlList()
|
||||
@bindKey 'up', 'moveUp'
|
||||
@bindKey 'down', 'moveDown'
|
||||
|
||||
bindKey: (pattern, methodName) ->
|
||||
@on 'keydown', (event) =>
|
||||
if window.keyEventMatchesPattern(event, pattern)
|
||||
this[methodName]()
|
||||
|
||||
populateUrlList: ->
|
||||
@urlList.empty()
|
||||
@@ -45,6 +52,3 @@ class FileFinder extends Template
|
||||
scoredUrls = ({url, score: stringScore(url, query)} for url in @urls)
|
||||
sortedUrls = scoredUrls.sort (a, b) -> a.score > b.score
|
||||
urlAndScore.url for urlAndScore in sortedUrls when urlAndScore.score > 0
|
||||
|
||||
handleKeydown: ->
|
||||
console.log 'keydownnnn'
|
||||
|
||||
@@ -49,15 +49,36 @@ windowAdditions =
|
||||
keys.altKey == event.altKey and
|
||||
keys.shiftKey == event.shiftKey and
|
||||
keys.metaKey == event.metaKey and
|
||||
event.which == keys.key.toUpperCase().charCodeAt 0
|
||||
event.which == keys.charCode
|
||||
|
||||
namedKeys:
|
||||
backspace: 8, tab: 9, clear: 12,
|
||||
enter: 13, 'return': 13,
|
||||
esc: 27, escape: 27, space: 32,
|
||||
left: 37, up: 38,
|
||||
right: 39, down: 40,
|
||||
del: 46, 'delete': 46,
|
||||
home: 36, end: 35,
|
||||
pageup: 33, pagedown: 34,
|
||||
',': 188, '.': 190, '/': 191,
|
||||
'`': 192, '-': 189, '=': 187,
|
||||
';': 186, '\'': 222,
|
||||
'[': 219, ']': 221, '\\': 220
|
||||
|
||||
parseKeyPattern: (pattern) ->
|
||||
[modifiers..., key] = pattern.split '+'
|
||||
|
||||
if window.namedKeys[key]
|
||||
charCode = window.namedKeys[key]
|
||||
key = null
|
||||
else
|
||||
charCode = key.toUpperCase().charCodeAt 0
|
||||
|
||||
ctrlKey: 'ctrl' in modifiers
|
||||
altKey: 'alt' in modifiers
|
||||
shiftKey: 'shift' in modifiers
|
||||
metaKey: 'meta' in modifiers
|
||||
charCode: charCode
|
||||
key: key
|
||||
|
||||
registerEventHandlers: ->
|
||||
@@ -68,6 +89,7 @@ windowAdditions =
|
||||
$(window).focus => @registerMenuItems()
|
||||
$(window).blur -> atom.native.resetMainMenu()
|
||||
|
||||
|
||||
registerMenuItems: ->
|
||||
for path, {pattern} of @menuItemActions
|
||||
atom.native.addMenuItem(path, pattern)
|
||||
|
||||
@@ -4,7 +4,7 @@ Builder = require 'template/builder'
|
||||
|
||||
module.exports =
|
||||
class Template
|
||||
@events: 'blur change click dblclick error focus keydown
|
||||
@events: 'blur change click dblclick error focus input keydown
|
||||
keypress keyup load mousedown mousemove mouseout mouseover
|
||||
mouseup resize scroll select submit unload'.split /\s+/
|
||||
|
||||
|
||||
Reference in New Issue
Block a user