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

Unified Diff: third_party/WebKit/Source/core/editing/SurroundingText.cpp

Issue 2928073002: Reland: Made surrounding text work for last word in a document (Closed)
Patch Set: Do not create surrounding text for control elements, updated layout tests Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 a4db50ce882c9ef697ab2b754c5edf6f876b7f16..af6e911fe8b8f0401061cac53fdaab8bb08f25a8 100644
--- a/third_party/WebKit/Source/core/editing/SurroundingText.cpp
+++ b/third_party/WebKit/Source/core/editing/SurroundingText.cpp
@@ -37,6 +37,7 @@
#include "core/editing/Position.h"
#include "core/editing/iterators/BackwardsCharacterIterator.h"
#include "core/editing/iterators/CharacterIterator.h"
+#include "core/html/HTMLFormControlElement.h"
namespace blink {
@@ -72,22 +73,21 @@ void SurroundingText::Initialize(const Position& start_position,
Element* const root_element =
root_editable ? root_editable : document->documentElement();
+ // Do not create surrounding text if start or end position is within a
+ // control.
+ if (HTMLFormControlElement::EnclosingFormControlElement(
+ start_position.ComputeContainerNode()) ||
+ HTMLFormControlElement::EnclosingFormControlElement(
+ end_position.ComputeContainerNode()))
+ return;
+
CharacterIterator forward_iterator(
end_position,
Position::LastPositionInNode(*root_element).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?
if (!forward_iterator.AtEnd())
forward_iterator.Advance(max_length - half_max_length);
- EphemeralRange forward_range = forward_iterator.Range();
- if (forward_range.IsNull() ||
- !Range::Create(*document, end_position, forward_range.StartPosition())
- ->GetText()
- .length())
- return;
-
// Same as with the forward range but with the backward range. The range
// starts at the document's or input element's start and ends at the selection
// start and will be updated.
@@ -105,7 +105,7 @@ void SurroundingText::Initialize(const Position& start_position,
end_offset_in_content_ = TextIterator::RangeLength(
backwards_iterator.EndPosition(), end_position, behavior);
content_range_ = Range::Create(*document, backwards_iterator.EndPosition(),
- forward_range.StartPosition());
+ forward_iterator.StartPosition());
DCHECK(content_range_);
}

Powered by Google App Engine
This is Rietveld 408576698