fix(composer): whilePreservingSelection should not call select if not activeElement

This commit is contained in:
Ben Gotow 2016-01-12 11:51:18 -08:00
parent 67a448db5d
commit c72e5099aa

View file

@ -36,6 +36,10 @@ class EditorAPI
currentSelection: -> @_extendedSelection
whilePreservingSelection: (fn) ->
# We only preserve selection if the active element is actually within the
# contenteditable. Otherwise, we can unintentionally "steal" focus back if
# `whilePreservingSelection` is called by a plugin when we are not focused.
return fn() unless document.activeElement is @rootNode or @rootNode.contains(document.activeElement)
sel = @currentSelection().exportSelection()
fn()
@select(sel)