Merge branch 'master' of github.com:github/atom

This commit is contained in:
Nathan Sobo
2012-03-20 13:09:48 -06:00
2 changed files with 30 additions and 1 deletions

View File

@@ -1,5 +1,7 @@
FileFinder = require 'file-finder'
{$$} = require 'space-pen'
describe 'FileFinder', ->
finder = null
urls = null
@@ -93,3 +95,22 @@ describe 'FileFinder', ->
expect(finder.findMatches('ap')).toEqual ["app.coffee", "atom/app.coffee"]
expect(finder.findMatches('a/ap')).toEqual ["atom/app.coffee"]
describe "when it is removed", ->
input = null
beforeEach ->
input = $$ -> @input value : "this has focus"
input.attachToDom()
input.focus()
expect(document.activeElement).toBe input[0]
finder = new FileFinder(urls: [])
finder.attachToDom()
expect(document.activeElement).not.toBe input[0]
afterEach ->
input.remove()
it "returns focus to previous active element", ->
finder.remove()
expect(document.activeElement).toBe input[0]

View File

@@ -16,10 +16,14 @@ class FileFinder extends View
initialize: ({@urls, @selected}) ->
requireStylesheet 'file-finder.css'
@maxResults = 10
@previousFocusedElement = $(document.activeElement)
@populateUrlList()
window.keymap.bindKeys ".file-finder .editor",
'enter': 'file-finder:select-file'
'enter': 'file-finder:select-file',
'escape': 'file-finder:close'
@on 'file-finder:close', => @remove()
@on 'move-up', => @moveUp()
@on 'move-down', => @moveDown()
@on 'file-finder:select-file', => @select()
@@ -43,6 +47,10 @@ class FileFinder extends View
@selected(filePath) if filePath and @selected
@remove()
remove: ->
super()
@previousFocusedElement.focus()
moveUp: ->
@findSelectedLi()
.filter(':not(:first-child)')