mirror of
https://github.com/atom/atom.git
synced 2026-01-24 06:18:03 -05:00
Bound up / down keys to moveUp / moveDown in fileFinder
This commit is contained in:
@@ -17,7 +17,7 @@ describe 'FileFinder', ->
|
||||
describe "when characters are typed into the input element", ->
|
||||
it "displays matching urls in the ol element and selects the first", ->
|
||||
finder.input.val('ap')
|
||||
finder.input.keyup()
|
||||
finder.input.trigger 'input'
|
||||
|
||||
expect(finder.urlList.children().length).toBe 2
|
||||
expect(finder.urlList.find('li:contains(app.coffee)').length).toBe 2
|
||||
@@ -27,12 +27,12 @@ describe 'FileFinder', ->
|
||||
|
||||
# we should clear the list before re-populating it
|
||||
finder.input.val('a/ap')
|
||||
finder.input.keyup()
|
||||
finder.input.trigger 'input'
|
||||
|
||||
expect(finder.urlList.children().length).toBe 1
|
||||
expect(finder.urlList.find('li:contains(atom/app.coffee)').length).toBe 1
|
||||
|
||||
fdescribe "moveDown / moveUp", ->
|
||||
describe "moveDown / moveUp", ->
|
||||
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"
|
||||
|
||||
@@ -32,13 +32,14 @@ describe "Window", ->
|
||||
expect(action2).not.toHaveBeenCalled()
|
||||
|
||||
describe 'keyEventMatchesPattern', ->
|
||||
it 'returns true if the modifiers and letter in the pattern match the key event', ->
|
||||
expectMatch = (pattern) ->
|
||||
expect(window.keyEventMatchesPattern(window.createKeyEvent(pattern), pattern)).toBeTruthy()
|
||||
expectMatch = (pattern) ->
|
||||
expect(window.keyEventMatchesPattern(window.createKeyEvent(pattern), pattern)).toBeTruthy()
|
||||
|
||||
expectNoMatch = (eventPattern, patternToTest) ->
|
||||
event = window.createKeyEvent(eventPattern)
|
||||
expect(window.keyEventMatchesPattern(event, patternToTest)).toBeFalsy()
|
||||
expectNoMatch = (eventPattern, patternToTest) ->
|
||||
event = window.createKeyEvent(eventPattern)
|
||||
expect(window.keyEventMatchesPattern(event, patternToTest)).toBeFalsy()
|
||||
|
||||
it 'returns true if the modifiers and letter in the pattern match the key event', ->
|
||||
|
||||
expectMatch 'meta+a'
|
||||
expectMatch 'meta+1'
|
||||
@@ -56,6 +57,9 @@ describe "Window", ->
|
||||
expectNoMatch 'meta+a', 'meta+b'
|
||||
expectNoMatch 'meta+1', 'alt+1'
|
||||
|
||||
it 'handles named special keys (e.g. arrows, home)', ->
|
||||
expectMatch 'up'
|
||||
|
||||
describe "bindMenuItem(path, keyPattern, action)", ->
|
||||
it "causes the given menu item to be added to the menu when the window is focused and removed when it is blurred", ->
|
||||
addedPaths = []
|
||||
|
||||
@@ -13,10 +13,16 @@ window.keydown = (pattern) ->
|
||||
|
||||
window.createKeyEvent = (pattern) ->
|
||||
keys = pattern.split '+'
|
||||
key = _.last(keys)
|
||||
|
||||
if window.namedKeys[key]
|
||||
key = window.namedKeys[key]
|
||||
else
|
||||
key = key.toUpperCase().charCodeAt 0
|
||||
|
||||
$.Event "keydown",
|
||||
ctrlKey: 'ctrl' in keys
|
||||
altKey: 'alt' in keys
|
||||
shiftKey: 'shift' in keys
|
||||
metaKey: 'meta' in keys
|
||||
which: _.last(keys).toUpperCase().charCodeAt 0
|
||||
|
||||
which: key
|
||||
|
||||
@@ -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