Focus root view if previously focused element is no longer attached

This can be the case when a select list is triggered while a different
select list is already open and so the second list to open has no
element to restore focus to when it closes.
This commit is contained in:
Kevin Sawicki
2013-06-24 16:46:36 -07:00
parent ab75f6f635
commit be354f78a6
2 changed files with 9 additions and 1 deletions

View File

@@ -151,7 +151,10 @@ class SelectList extends View
@previouslyFocusedElement = $(':focus')
restoreFocus: ->
@previouslyFocusedElement?.focus()
if @previouslyFocusedElement?.isOnDom()
@previouslyFocusedElement.focus()
else
rootView.focus()
cancelled: ->
@miniEditor.setText('')

View File

@@ -36,6 +36,11 @@ class GoToLineView extends View
@detaching = true
@miniEditor.setText('')
if @previouslyFocusedElement?.isOnDom()
@previouslyFocusedElement.focus()
else
rootView.focus()
super
@detaching = false