Index: Source/core/editing/htmlediting.cpp |
diff --git a/Source/core/editing/htmlediting.cpp b/Source/core/editing/htmlediting.cpp |
index 858d2e4a51e38575cdd74a96aad6ef3aa0aaad5c..5b6301b067ce55a694b373531cfdce9732f44782 100644 |
--- a/Source/core/editing/htmlediting.cpp |
+++ b/Source/core/editing/htmlediting.cpp |
@@ -51,6 +51,7 @@ |
#include "core/html/HTMLUListElement.h" |
#include "core/page/Frame.h" |
#include "core/rendering/RenderObject.h" |
+#include "core/rendering/RenderText.h" |
#include "wtf/Assertions.h" |
#include "wtf/StdLibExtras.h" |
#include "wtf/text/StringBuilder.h" |
@@ -971,7 +972,11 @@ int caretMinOffset(const Node* n) |
{ |
RenderObject* r = n->renderer(); |
ASSERT(!n->isCharacterDataNode() || !r || r->isText()); // FIXME: This was a runtime check that seemingly couldn't fail; changed it to an assertion for now. |
- return r ? r->caretMinOffset() : 0; |
+ if (!r) |
+ return 0; |
+ if (r->isText()) |
+ return r->caretMinOffset() + toRenderText(r)->textStartOffset(); |
+ return r->caretMinOffset(); |
} |
// If a node can contain candidates for VisiblePositions, return the offset of the last candidate, otherwise |
@@ -979,8 +984,9 @@ int caretMinOffset(const Node* n) |
int caretMaxOffset(const Node* n) |
{ |
// For rendered text nodes, return the last position that a caret could occupy. |
- if (n->isTextNode() && n->renderer()) |
- return n->renderer()->caretMaxOffset(); |
+ RenderObject* renderer = n->renderer(); |
+ if (renderer && renderer->isText()) |
+ return renderer->caretMaxOffset() + toRenderText(renderer)->textStartOffset(); |
// For containers return the number of children. For others do the same as above. |
return lastOffsetForEditing(n); |
} |