Fix hasFocus() for editors nested in contenteditable elements #189
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "fix-nested-contenteditable"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem
When a ProseMirror editor is nested inside another element with
contenteditable="true",view.hasFocus()incorrectly returnsfalseeven when the editor has focus. This causes various functionality to break, including selection handling.Cause
When the editor is inside a contenteditable ancestor, the browser sets
document.activeElementto the outermost contenteditable element rather than the editor's DOM element. The existinghasFocus()implementation comparesactiveElementdirectly tothis.dom, which fails in this nested scenario.Solution
Added an
effectiveActiveElement()helper method that accounts for nested contenteditable elements. WhenactiveElementis an ancestor that containsthis.dom, the helper returnsthis.domas the effective active element. ThehasFocus()method now uses this helper instead of directly accessingthis.root.activeElement.Testing
hasFocus()returns true when the editor is mounted inside a contenteditable wrapperWhich browser does this?
I tested this in Chrome on OSX.
I just verified that, on MacOS Chrome, focusing an editable element inside another editable element sets
document.activeElementto the inner element. All other browsers behave the same. This is the test I used.Possibly you don't have an uneditable element around the inner editable element. That will make it part of the outer editable region.
Pull request closed