Index: third_party/WebKit/Source/core/editing/iterators/TextIterator.cpp |
diff --git a/third_party/WebKit/Source/core/editing/iterators/TextIterator.cpp b/third_party/WebKit/Source/core/editing/iterators/TextIterator.cpp |
index d7c94cbae624651be48ff5adf40405ab76ca02c0..310a27d98893de737cb8e0dadc2d1ca53669846e 100644 |
--- a/third_party/WebKit/Source/core/editing/iterators/TextIterator.cpp |
+++ b/third_party/WebKit/Source/core/editing/iterators/TextIterator.cpp |
@@ -458,8 +458,15 @@ bool TextIteratorAlgorithm<Strategy>::handleTextNode() |
if (!layoutObject->style()->collapseWhiteSpace()) { |
int runStart = m_offset; |
if (m_lastTextNodeEndedWithCollapsedSpace && hasVisibleTextNode(layoutObject)) { |
- emitCharacter(spaceCharacter, textNode, 0, runStart, runStart); |
- return false; |
+ if (m_behavior & TextIteratorCollapseTrailingSpace) { |
+ if (runStart > 0 && str[runStart - 1] == ' ') { |
+ emitCharacter(spaceCharacter, textNode, 0, runStart, runStart); |
yosin_UTC9
2016/01/20 05:33:11
Off-topic:
It seems we should rename |emitCharacte
ramya.v
2016/01/20 05:59:10
Sure will upload a separate patch for same.
|
+ return false; |
+ } |
+ } else { |
+ emitCharacter(spaceCharacter, textNode, 0, runStart, runStart); |
+ return false; |
+ } |
} |
if (!m_handledFirstLetter && layoutObject->isTextFragment() && !m_offset) { |
handleTextNodeFirstLetter(toLayoutTextFragment(layoutObject)); |
@@ -671,7 +678,15 @@ bool TextIteratorAlgorithm<Strategy>::handleReplacedElement() |
return true; |
} |
- if (m_lastTextNodeEndedWithCollapsedSpace) { |
+ if (m_behavior & TextIteratorCollapseTrailingSpace) { |
+ if (m_lastTextNode) { |
+ String str = m_lastTextNode->layoutObject()->text(); |
+ if (m_lastTextNodeEndedWithCollapsedSpace && m_offset > 0 && str[m_offset - 1] == ' ') { |
+ emitCharacter(spaceCharacter, Strategy::parent(*m_lastTextNode), m_lastTextNode, 1, 1); |
+ return false; |
+ } |
+ } |
+ } else if (m_lastTextNodeEndedWithCollapsedSpace) { |
emitCharacter(spaceCharacter, Strategy::parent(*m_lastTextNode), m_lastTextNode, 1, 1); |
return false; |
} |