From b338e16b432e6bfd40c84587175b7f8146314ac8 Mon Sep 17 00:00:00 2001 From: "peterv%propagandism.org" Date: Thu, 19 Jul 2007 09:47:49 +0000 Subject: [PATCH] Fix for bug 386300 (Caret disappears when pressing UP at the top of a contenteditable region). r/sr=jst. git-svn-id: svn://10.0.0.236/trunk@230280 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/layout/base/nsPresShell.cpp | 36 +++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/mozilla/layout/base/nsPresShell.cpp b/mozilla/layout/base/nsPresShell.cpp index 40b80a7e03f..eb2301f9a72 100644 --- a/mozilla/layout/base/nsPresShell.cpp +++ b/mozilla/layout/base/nsPresShell.cpp @@ -2802,6 +2802,42 @@ PresShell::CompleteMove(PRBool aForward, PRBool aExtend) nsresult PresShell::CompleteMoveInner(PRBool aForward, PRBool aExtend, PRBool aScrollIntoView) { + nsIContent* root = mSelection->GetAncestorLimiter(); + if (root) { + // make the caret be either at the very beginning (0) or the very end + nsIContent* node = root; + PRInt32 offset = 0; + nsFrameSelection::HINT hint = nsFrameSelection::HINTLEFT; + if (aForward) { + nsIContent* next = node; + PRUint32 count; + while ((count = next->GetChildCount()) > 0) { + node = next; + offset = count; + next = next->GetChildAt(count - 1); + } + + if (offset > 0 && node->GetChildAt(offset - 1)->Tag() == nsGkAtoms::br) { + --offset; + hint = nsFrameSelection::HINTRIGHT; // for bug 106855 + } + } + + mSelection->HandleClick(node, offset, offset, aExtend, PR_FALSE, hint); + + // HandleClick resets ancestorLimiter, so set it again. + mSelection->SetAncestorLimiter(root); + + if (aScrollIntoView) { + return + ScrollSelectionIntoView(nsISelectionController::SELECTION_NORMAL, + nsISelectionController::SELECTION_FOCUS_REGION, + PR_TRUE); + } + + return NS_OK; + } + nsIScrollableView *scrollableView; if (!mViewManager) return NS_ERROR_UNEXPECTED;