Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(649)

Issue 2340223002: DevTools: fix ViewportControl's text selection logic (Closed)

Created:
4 years, 3 months ago by luoe
Modified:
4 years, 3 months ago
Reviewers:
lushnikov
CC:
chromium-reviews, caseq+blink_chromium.org, lushnikov+blink_chromium.org, pfeldman+blink_chromium.org, apavlov+blink_chromium.org, devtools-reviews_chromium.org, blink-reviews, pfeldman, kozyatinskiy+blink_chromium.org
Target Ref:
refs/pending/heads/master
Project:
chromium
Visibility:
Public.

Description

DevTools: 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 #

Unified diffs Side-by-side diffs Delta from patch set Stats (+30 lines, -1 line) Patch
M third_party/WebKit/LayoutTests/inspector/console/console-viewport-selection.html View 1 2 1 chunk +21 lines, -0 lines 0 comments Download
M third_party/WebKit/LayoutTests/inspector/console/console-viewport-selection-expected.txt View 1 2 1 chunk +8 lines, -0 lines 0 comments Download
M third_party/WebKit/Source/devtools/front_end/ui/ViewportControl.js View 1 chunk +1 line, -1 line 0 comments Download

Messages

Total messages: 14 (5 generated)
luoe
PTAL
4 years, 3 months ago (2016-09-15 17:01:25 UTC) #3
lushnikov
can we add a few tests for this?
4 years, 3 months ago (2016-09-15 17:38:19 UTC) #4
luoe
Test added for selection when the base/extent is not a text node.
4 years, 3 months ago (2016-09-16 01:10:32 UTC) #5
luoe
PTAL
4 years, 3 months ago (2016-09-16 01:10:44 UTC) #6
lushnikov
lgtm please, make sure the test fails without your fix
4 years, 3 months ago (2016-09-16 16:43:53 UTC) #7
luoe
Thanks! Yes, on the old node !== container, running the test selects 2 full lines ...
4 years, 3 months ago (2016-09-16 17:22:51 UTC) #8
commit-bot: I haz the power
CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/v2/patch-status/codereview.chromium.org/2340223002/40001
4 years, 3 months ago (2016-09-16 17:23:36 UTC) #10
commit-bot: I haz the power
Committed patchset #3 (id:40001)
4 years, 3 months ago (2016-09-16 18:36:06 UTC) #12
commit-bot: I haz the power
4 years, 3 months ago (2016-09-16 18:38:34 UTC) #14
Message was sent while issue was closed.
Patchset 3 (id:??) landed as
https://crrev.com/1aee657f2d27df3cad42453428b527f592d29885
Cr-Commit-Position: refs/heads/master@{#419227}

Powered by Google App Engine
This is Rietveld 408576698