DescriptionDevTools: fix ViewportControl's text selection logic
ViewportControl's _selectedText currently does this:
1 - get a selection+range with native window/shadowRoot.getSelection()
2 - calculate first and last viewport items that are part of the selection
3 - get the deepTextContent() of all those items
4 - trim out text based on the offsets provided by the selection
Step 4 is done by _textOffsetInNode(), which takes an itemElement, container,
and offset. Beforethis CL, it would start at the item and traverse all text
nodes until it stops at the container (node !== container). In this logic, it
assumes that the container is a text node itself so that (node !== container)
will be false and we will stop before counting the container's text length. In
reality, a user can drag to create a selection where the
range.start/endContainer can be an element that is not a text node (e.g. <span>
containing a text node). Then, _textOffsetInNode() would continue to traverse
and node.traverseNextTextNode() will never return a node that is === container.
This results in extra text length being counted which breaks the offset logic.
This CL makes sure that in those cases where the range.start/endContainer is not
a text node, such as a <span> containing the boundary text, we will stop
traversing when we hit a text node that is the end or is a descendant.
BUG=647287
Committed: https://crrev.com/1aee657f2d27df3cad42453428b527f592d29885
Cr-Commit-Position: refs/heads/master@{#419227}
Patch Set 1 #Patch Set 2 : add test #Patch Set 3 : add test #
Messages
Total messages: 14 (5 generated)
|