fix wxTextCtrl::Replace() under wxGTK; added unit test for it and describe its effect on the insertion point

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@57253 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2008-12-11 16:46:25 +00:00
parent 18e046a7c5
commit 059979d848
4 changed files with 34 additions and 1 deletions

View File

@@ -1476,6 +1476,9 @@ public:
Removes the text starting at the first given position up to Removes the text starting at the first given position up to
(but not including) the character at the last position. (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 @param from
The first position. The first position.
@param to @param to
@@ -1487,6 +1490,9 @@ public:
Replaces the text starting at the first position up to Replaces the text starting at the first position up to
(but not including) the character at the last position with the given text. (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 @param from
The first position. The first position.
@param to @param to

View File

@@ -73,6 +73,7 @@ void wxTextEntryBase::Replace(long from, long to, const wxString& value)
Remove(from, to); Remove(from, to);
} }
SetInsertionPoint(from);
WriteText(value); WriteText(value);
} }

View File

@@ -165,3 +165,27 @@ void TextEntryTestCase::InsertionPoint()
CPPUNIT_ASSERT_EQUAL( 1, entry->GetInsertionPoint() ); 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());
}

View File

@@ -37,12 +37,14 @@ protected:
CPPUNIT_TEST( SetValue ); \ CPPUNIT_TEST( SetValue ); \
CPPUNIT_TEST( TextChangeEvents ); \ CPPUNIT_TEST( TextChangeEvents ); \
CPPUNIT_TEST( Selection ); \ CPPUNIT_TEST( Selection ); \
CPPUNIT_TEST( InsertionPoint ) CPPUNIT_TEST( InsertionPoint ); \
CPPUNIT_TEST( Replace )
void SetValue(); void SetValue();
void TextChangeEvents(); void TextChangeEvents();
void Selection(); void Selection();
void InsertionPoint(); void InsertionPoint();
void Replace();
private: private:
// Selection() test helper: verify that selection is as described by the // Selection() test helper: verify that selection is as described by the