Index: Source/core/editing/TextIterator.cpp |
diff --git a/Source/core/editing/TextIterator.cpp b/Source/core/editing/TextIterator.cpp |
index b85b148eaf9608052ac88662b451df18dd732357..bc1489664e7d454106a0d2535660358d49b5cf85 100644 |
--- a/Source/core/editing/TextIterator.cpp |
+++ b/Source/core/editing/TextIterator.cpp |
@@ -259,6 +259,7 @@ TextIterator::TextIterator(const Range* range, TextIteratorBehaviorFlags behavio |
, m_shouldStop(false) |
, m_emitsImageAltText(behavior & TextIteratorEmitsImageAltText) |
, m_entersAuthorShadowRoots(behavior & TextIteratorEntersAuthorShadowRoots) |
+ , m_hasNodesFollowing(behavior & TextIteratorBehavesAsIfNodesFollowing) |
{ |
if (!range) |
return; |
@@ -663,9 +664,12 @@ void TextIterator::handleTextBox() |
m_offset = runStart + 1; |
} else { |
size_t subrunEnd = str.find('\n', runStart); |
- if (subrunEnd == kNotFound || subrunEnd > runEnd) |
+ if (subrunEnd == kNotFound || subrunEnd > runEnd) { |
subrunEnd = runEnd; |
- |
+ bool lastSpaceCollapsedByNextNonTextBox = !nextTextBox && m_hasNodesFollowing && (str.length() > runEnd); |
+ if (lastSpaceCollapsedByNextNonTextBox) |
+ subrunEnd++; // runEnd stopped before last space. Increment by one to restore the space. |
+ } |
m_offset = subrunEnd; |
emitText(m_node, renderer, runStart, subrunEnd); |
} |