Restore focus after select list detaches

Previously if the select list was cancelled with no open
editors the mini editor would be given focus before being
detached causing nothing to have focus after detach completed.

Now the select list tracks the previously focused elements and
restores focus to that element at the end of the cancel.
This commit is contained in:
Kevin Sawicki
2013-01-23 09:32:49 -08:00
parent f0aa9c136f
commit 001bb3a862
6 changed files with 48 additions and 17 deletions

View File

@@ -37,7 +37,6 @@ class GrammarView extends SelectList
cancelled: ->
@miniEditor.setText('')
@editor.rootView()?.focus() if @miniEditor.isFocused
confirmed: (grammar) ->
@cancel()
@@ -48,5 +47,7 @@ class GrammarView extends SelectList
@editor.reloadGrammar()
attach: ->
super
@editor.rootView()?.append(this)
@miniEditor.focus()

View File

@@ -121,10 +121,21 @@ class SelectList extends View
else
@cancel()
attach: ->
@storeFocusedElement()
storeFocusedElement: ->
@previouslyFocusedElement = $(':focus')
restoreFocus: ->
@previouslyFocusedElement?.focus()
cancel: ->
@list.empty()
@cancelling = true
miniEditorFocused = @miniEditor.isFocused
@cancelled()
@detach()
@restoreFocus() if miniEditorFocused
@cancelling = false
clearTimeout(@scheduleTimeout)