]> git.saurik.com Git - wxWidgets.git/commitdiff
Fix for bug #14915 - wxRichTextCtrl: Not able to move up to empty first line
authorJulian Smart <julian@anthemion.co.uk>
Sat, 22 Dec 2012 21:31:13 +0000 (21:31 +0000)
committerJulian Smart <julian@anthemion.co.uk>
Sat, 22 Dec 2012 21:31:13 +0000 (21:31 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@73258 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/richtext/richtextctrl.cpp

index 9d98c4fe644e4540ac1ba0e20ca20ca7eb6b927b..d4408a8b8a62fed7f7e5c3ec6055a035edac1889 100644 (file)
@@ -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;