Bug 1259949 - Set the CARET_ASSOCIATE_AFTER hint also when we collapse just after a text node that ends with a significant newline. r=ehsan
nsCaret::GetFrameAndOffset may return a text frame also when aParentNode
is the container of a text node and aOffset is just after it. In this
case we also want CARET_ASSOCIATE_AFTER if the text ends with
a significant newline. (follow-up from
bug 1258308)
--- a/layout/generic/nsSelection.cpp
+++ b/layout/generic/nsSelection.cpp
@@ -4932,25 +4932,27 @@ Selection::Collapse(nsINode& aParentNode
// Delete all of the current ranges
Clear(presContext);
// Turn off signal for table selection
mFrameSelection->ClearTableCellSelection();
// Hack to display the caret on the right line (bug 1237236).
- if (aParentNode.IsContent()) {
- nsTextFrame* f = do_QueryFrame(aParentNode.AsContent()->GetPrimaryFrame());
- if (f) {
- int32_t frameOffset;
- f = do_QueryFrame(nsCaret::GetFrameAndOffset(this, &aParentNode,
- aOffset, &frameOffset));
- }
+ if (mFrameSelection->GetHint() != CARET_ASSOCIATE_AFTER &&
+ aParentNode.IsContent()) {
+ int32_t frameOffset;
+ nsTextFrame* f =
+ do_QueryFrame(nsCaret::GetFrameAndOffset(this, &aParentNode,
+ aOffset, &frameOffset));
if (f && f->IsAtEndOfLine() && f->HasSignificantTerminalNewline()) {
- if (f->GetContentEnd() == int32_t(aOffset)) {
+ if ((aParentNode.AsContent() == f->GetContent() &&
+ f->GetContentEnd() == int32_t(aOffset)) ||
+ (&aParentNode == f->GetContent()->GetParentNode() &&
+ aParentNode.IndexOf(f->GetContent()) + 1 == int32_t(aOffset))) {
mFrameSelection->SetHint(CARET_ASSOCIATE_AFTER);
}
}
}
RefPtr<nsRange> range = new nsRange(&aParentNode);
result = range->SetEnd(&aParentNode, aOffset);
if (NS_FAILED(result)) {