Index: third_party/WebKit/Source/core/editing/SurroundingText.cpp |
diff --git a/third_party/WebKit/Source/core/editing/SurroundingText.cpp b/third_party/WebKit/Source/core/editing/SurroundingText.cpp |
index 4a7d5f0965e3495af3f4f1209c9e8795e626f7bc..b450624cc3ebd4430340f8d5dbdfb9c9419748cd 100644 |
--- a/third_party/WebKit/Source/core/editing/SurroundingText.cpp |
+++ b/third_party/WebKit/Source/core/editing/SurroundingText.cpp |
@@ -62,13 +62,22 @@ void SurroundingText::Initialize(const Position& start_position, |
return; |
DCHECK(!document->NeedsLayoutTreeUpdate()); |
- // The forward range starts at the selection end and ends at the document's |
- // end. It will then be updated to only contain the text in the text in the |
- // right range around the selection. |
+ // The forward range starts at the selection end and ends at the end of the |
+ // root container: either document's end or the end of shadow root for input |
+ // elements. It will then be updated to only contain the text in the text in |
+ // the right range around the selection. |
+ |
+ Node* end_root_container = end_position.ComputeContainerNode(); |
yosin_UTC9
2017/06/05 04:59:32
You can do this by
Node* end_container = end_pos
Tima Vaisburd
2017/06/06 23:39:09
I used RootEditableElementOf() eventually, I thoug
|
+ while (end_root_container->parentNode()) |
+ end_root_container = end_root_container->parentNode(); |
+ |
+ Node* last_node = end_root_container->IsShadowRoot() |
yosin_UTC9
2017/06/05 04:59:32
The name |last_node| is confusion. Usually, docume
Tima Vaisburd
2017/06/06 23:39:09
Not used anymore.
|
+ ? end_root_container |
+ : document->documentElement(); |
+ |
CharacterIterator forward_iterator( |
end_position, |
- Position::LastPositionInNode(document->documentElement()) |
- .ParentAnchoredEquivalent(), |
+ Position::LastPositionInNode(last_node).ParentAnchoredEquivalent(), |
TextIteratorBehavior::Builder().SetStopsOnFormControls(true).Build()); |
// FIXME: why do we stop going trough the text if we were not able to select |
// something on the right? |
@@ -82,12 +91,19 @@ void SurroundingText::Initialize(const Position& start_position, |
.length()) |
return; |
+ Node* start_root_container = start_position.ComputeContainerNode(); |
+ while (start_root_container->parentNode()) |
+ start_root_container = start_root_container->parentNode(); |
+ |
+ Node* first_node = start_root_container->IsShadowRoot() |
+ ? start_root_container |
+ : document->documentElement(); |
+ |
// Same as with the forward range but with the backward range. The range |
// starts at the document's start and ends at the selection start and will |
// be updated. |
BackwardsCharacterIterator backwards_iterator( |
- Position::FirstPositionInNode(document->documentElement()) |
- .ParentAnchoredEquivalent(), |
+ Position::FirstPositionInNode(first_node).ParentAnchoredEquivalent(), |
start_position, |
TextIteratorBehavior::Builder().SetStopsOnFormControls(true).Build()); |
if (!backwards_iterator.AtEnd()) |