caretRangeFromPoint and Shadow Root

421 views
Skip to first unread message

nazar.mo...@gmail.com

unread,
Oct 17, 2015, 10:51:36 PM10/17/15
to blink-dev
I'm working on Shadow DOM support in TinyMCE (namely, make it working under Shadow DOM).
It is quite big piece of software, but everything seems to be quite good so far.

The problem I've faced currently is with `document.caretRangeFromPoint()` method called in `drop` event handler after dragging text selection within `<p>` element.
When `div[contenteditable=true]` is under Shadow DOM this method returns Range where all relevant properties (commonAncestorContainer, endContainer and startContainer) contain direct parent of shadow's host element, while I expect text node.
So, I'm getting: `html > body > form`.
While I was expecting: `html > body > form > x-editor::shadow > div[contenteditable] > p > TEXT_NODE
TEXT_NODE is where content was dropped, so text from one `<p>` dragged and dropped at the end of another.

Is this an expected behavior and how to workaround that if so?
Chromium 45.0.2454.101.

Yoshifumi Inoue

unread,
Oct 19, 2015, 12:13:48 AM10/19/15
to nazar.mo...@gmail.com, blink-dev
Thanks for using shadowDOM.

To get caret position in shadow tree, you need to use ShadowRoot.caretPositionFromPoint(x, y) instead of Document.caretPositionFromPoint(x, y)

However, current Blink doesn't implement caretPositionFromPoint() on Document and ShadowRoot. Note: caretRangeFromPoint() is replaced by caretPointFromPoint() in current CSSOM specification.

Please start following bug in Blink issue tracker to raise priority of implementing caretPositionFromPoint()

Thanks!
-yosi




2015年10月18日(日) 11:51 <nazar.mo...@gmail.com>:

anton

unread,
Sep 16, 2024, 11:39:39 AMSep 16
to blink-dev, Yoshifumi Inoue, nazar.mo...@gmail.com
Is it possible to call caretPositionFromPoint() for shadowRoot?
понедельник, 19 октября 2015 г. в 09:13:48 UTC+5, Yoshifumi Inoue:

Siye Liu

unread,
Sep 16, 2024, 5:05:52 PMSep 16
to blink-dev, anton, Yoshifumi Inoue, nazar.mo...@gmail.com
Hello,

the caretRangeFromPoint API spec was recently changed: CSSOM View Module (csswg.org). The API now takes a caretpositionfrompointoptions argument which takes an array of shadow roots which can be pierced into by the API.

Chromium has implemented the API and is enabled by default. Can you give it a try and see if it can solve your problem?

Thanks,
Siye

Reply all
Reply to author
Forward
0 new messages