mirror of
https://github.com/atom/atom.git
synced 2026-01-23 13:58:08 -05:00
Merge branch 'master' of github.com:github/atom
This commit is contained in:
@@ -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]
|
||||
|
||||
@@ -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)')
|
||||
|
||||
Reference in New Issue
Block a user