diff --git a/interface/wx/textentry.h b/interface/wx/textentry.h index 7af88079be..70f7017526 100644 --- a/interface/wx/textentry.h +++ b/interface/wx/textentry.h @@ -533,7 +533,8 @@ public: would return @false immediately after the call to SetValue(). The insertion point is set to the start of the control (i.e. position - 0) by this function. + 0) by this function unless the control value doesn't change at all, in + which case the insertion point is left at its original position. Note that, unlike most other functions changing the controls values, this function generates a @c wxEVT_TEXT event. To avoid diff --git a/src/gtk/textentry.cpp b/src/gtk/textentry.cpp index 824514fed6..8518483530 100644 --- a/src/gtk/textentry.cpp +++ b/src/gtk/textentry.cpp @@ -570,12 +570,16 @@ void wxTextEntry::DoSetValue(const wxString& value, int flags) EventsSuppressor noevents(this); WriteText(value); } + + // Changing the value is supposed to reset the insertion point. Note, + // however, that this does not happen if the text doesn't really change. + SetInsertionPoint(0); } + // OTOH we must send the event even if the text didn't really change for + // consistency. if ( flags & SetValue_SendEvent ) SendTextUpdatedEvent(GetEditableWindow()); - - SetInsertionPoint(0); } wxString wxTextEntry::DoGetValue() const diff --git a/tests/controls/textentrytest.cpp b/tests/controls/textentrytest.cpp index b053e80489..0bda950169 100644 --- a/tests/controls/textentrytest.cpp +++ b/tests/controls/textentrytest.cpp @@ -165,6 +165,12 @@ void TextEntryTestCase::InsertionPoint() CPPUNIT_ASSERT_EQUAL( 3, entry->GetLastPosition() ); CPPUNIT_ASSERT_EQUAL( 1, entry->GetInsertionPoint() ); + entry->SetValue("012"); // shouldn't change the position if no real change + CPPUNIT_ASSERT_EQUAL( 1, entry->GetInsertionPoint() ); + + entry->ChangeValue("012"); // same as for SetValue() + CPPUNIT_ASSERT_EQUAL( 1, entry->GetInsertionPoint() ); + entry->SetInsertionPointEnd(); CPPUNIT_ASSERT_EQUAL( 3, entry->GetInsertionPoint() );