-
Notifications
You must be signed in to change notification settings - Fork 413
Description
Hello, I've been working on getting Squire working within a Polymer application, but I initially ran into a couple problems. Primary issues included the application failing to properly track cursor location, similar issues with text editing, and several issues vaguely related to focus. After tinkering with squire-raw.js for a while, it seems like the issue was being caused by two functions in particular, Squire.prototype.fireEvent and getWindowSelection.
With Squire.prototype.fireEvent, the line isFocused = this._root === this._doc.activeElement;
is referencing the activeElement
on this._doc
, which is a direct reference to the document node. The issue arises because shadow DOMs have their own activeElement
property, and therefore the shadow root that a given node is attached to is the only one capable of directly observing that node. When a node nested within a shadow DOM is active, the document can only see that the shadow host of that node is active, and thus the focus check fails since it compares the nested node to the 'active' shadow host. My workaround has been to replace the aforementioned line with isFocused = this._root === this._root.getRootNode().activeElement
, which instead references the activeElement
of the node to which the element is directly attached.
Similarly, the issue with getWindowSelection
arises because it references the getSelection
method of self._win
, when it should reference the shadow root's. My solution was to replace the implementation with return self._root.getRootNode().getSelection() || null;
Thanks, and let me know if I missed anything.