From 76e36b9452b483cf2ec99386ac1e7046ff47b06f Mon Sep 17 00:00:00 2001 From: Julian Smart Date: Sat, 22 Dec 2012 21:31:13 +0000 Subject: [PATCH] Fix for bug #14915 - wxRichTextCtrl: Not able to move up to empty first line git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@73258 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/richtext/richtextctrl.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/richtext/richtextctrl.cpp b/src/richtext/richtextctrl.cpp index 9d98c4fe64..d4408a8b8a 100644 --- a/src/richtext/richtextctrl.cpp +++ b/src/richtext/richtextctrl.cpp @@ -2082,6 +2082,7 @@ bool wxRichTextCtrl::MoveDown(int noLines, int flags) wxRichTextParagraphLayoutBox* container = GetFocusObject(); int hitTestFlags = wxRICHTEXT_HITTEST_NO_NESTED_OBJECTS|wxRICHTEXT_HITTEST_NO_FLOATING_OBJECTS|wxRICHTEXT_HITTEST_HONOUR_ATOMIC; + bool lineIsEmpty = false; if (notInThisObject) { // If we know we're navigating out of the current object, @@ -2102,7 +2103,11 @@ bool wxRichTextCtrl::MoveDown(int noLines, int flags) { wxRichTextLine* lineObj = GetFocusObject()->GetLineForVisibleLineNumber(newLine); if (lineObj) + { pt.y = lineObj->GetAbsolutePosition().y + 2; + if (lineObj->GetRange().GetStart() == lineObj->GetRange().GetEnd()) + lineIsEmpty = true; + } else return false; } @@ -2134,6 +2139,15 @@ bool wxRichTextCtrl::MoveDown(int noLines, int flags) } bool caretLineStart = true; + + // If the line is empty, there is only one possible position for the caret, + // so force the 'before' state so FindCaretPositionForCharacterPosition doesn't + // just return the same position. + if (lineIsEmpty) + { + hitTest &= ~wxRICHTEXT_HITTEST_AFTER; + hitTest |= wxRICHTEXT_HITTEST_BEFORE; + } long caretPosition = FindCaretPositionForCharacterPosition(newPos, hitTest, container, caretLineStart); long newSelEnd = caretPosition; bool extendSel; -- 2.45.2