mirror of
https://github.com/atom/atom.git
synced 2026-04-28 03:01:47 -04:00
Previously focused element regains focus when file finder is removed
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,6 +16,8 @@ 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',
|
||||
@@ -45,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