]> git.saurik.com Git - wxWidgets.git/commitdiff
fix wxTextCtrl::Replace() under wxGTK; added unit test for it and describe its effect...
authorVadim Zeitlin <vadim@wxwidgets.org>
Thu, 11 Dec 2008 16:46:25 +0000 (16:46 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Thu, 11 Dec 2008 16:46:25 +0000 (16:46 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@57253 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

interface/wx/textctrl.h
src/common/textentrycmn.cpp
tests/controls/textentrytest.cpp
tests/controls/textentrytest.h

index f5f35e670c1f047fcf195432b898f6a21afe915c..e6f3aae4aceacf1241d87d0f781718ac39a3f9c3 100644 (file)
@@ -1476,6 +1476,9 @@ public:
         Removes the text starting at the first given position up to
         (but not including) the character at the last position.
 
+        This function puts the current insertion point position at @a to as a
+        side effect.
+
         @param from
             The first position.
         @param to
@@ -1487,6 +1490,9 @@ public:
         Replaces the text starting at the first position up to
         (but not including) the character at the last position with the given text.
 
+        This function puts the current insertion point position at @a to as a
+        side effect.
+
         @param from
             The first position.
         @param to
index 8e0551c3dbac703c86d23859cbc64cf0ace15b9e..b179499381aabc301d04f1350149301da92d740e 100644 (file)
@@ -73,6 +73,7 @@ void wxTextEntryBase::Replace(long from, long to, const wxString& value)
         Remove(from, to);
     }
 
+    SetInsertionPoint(from);
     WriteText(value);
 }
 
index 03adf476800945f205ff26db2b577cd3b1d130fe..9b5bf74f06f5041fa9ae5619c809cfba1b0b36c2 100644 (file)
@@ -165,3 +165,27 @@ void TextEntryTestCase::InsertionPoint()
     CPPUNIT_ASSERT_EQUAL( 1, entry->GetInsertionPoint() );
 }
 
+void TextEntryTestCase::Replace()
+{
+    wxTextEntry * const entry = GetTestEntry();
+
+    entry->SetValue("Hello replace\n"
+                    "0123456789012");
+    entry->SetInsertionPoint(0);
+
+    entry->Replace(6, 13, "changed");
+
+    CPPUNIT_ASSERT_EQUAL("Hello changed\n"
+                         "0123456789012",
+                         entry->GetValue());
+    CPPUNIT_ASSERT_EQUAL(13, entry->GetInsertionPoint());
+
+    entry->Replace(13, -1, "");
+    CPPUNIT_ASSERT_EQUAL("Hello changed", entry->GetValue());
+    CPPUNIT_ASSERT_EQUAL(13, entry->GetInsertionPoint());
+
+    entry->Replace(0, 6, "Un");
+    CPPUNIT_ASSERT_EQUAL("Unchanged", entry->GetValue());
+    CPPUNIT_ASSERT_EQUAL(2, entry->GetInsertionPoint());
+}
+
index b8376ddde056bce576a9a2b0ecdc46d5e2a4b92a..88147720209caeccea31d304b85dc0c40ed644db 100644 (file)
@@ -37,12 +37,14 @@ protected:
         CPPUNIT_TEST( SetValue ); \
         CPPUNIT_TEST( TextChangeEvents ); \
         CPPUNIT_TEST( Selection ); \
-        CPPUNIT_TEST( InsertionPoint )
+        CPPUNIT_TEST( InsertionPoint ); \
+        CPPUNIT_TEST( Replace )
 
     void SetValue();
     void TextChangeEvents();
     void Selection();
     void InsertionPoint();
+    void Replace();
 
 private:
     // Selection() test helper: verify that selection is as described by the