Replace() optimization for single line controls restored
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/wxUNIVERSAL@8575 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -488,6 +488,48 @@ void wxTextCtrl::Replace(long from, long to, const wxString& text)
|
||||
|
||||
#else // 1 (new replacement code)
|
||||
|
||||
if ( IsSingleLine() )
|
||||
{
|
||||
// replace the part of the text with the new value
|
||||
wxString valueNew(m_value, (size_t)from);
|
||||
|
||||
// remember it for later use
|
||||
wxCoord startNewText = GetTextWidth(valueNew);
|
||||
|
||||
valueNew += text;
|
||||
if ( (size_t)to < m_value.length() )
|
||||
{
|
||||
valueNew += m_value.c_str() + (size_t)to;
|
||||
}
|
||||
|
||||
// OPT: is the following really ok? not sure any more now at 2 am...
|
||||
|
||||
// we usually refresh till the end of line except of the most common case
|
||||
// when some text is appended to the end of the string in which case we
|
||||
// refresh just it
|
||||
wxCoord widthNewText;
|
||||
|
||||
if ( (size_t)from < m_value.length() )
|
||||
{
|
||||
// refresh till the end of line
|
||||
widthNewText = 0;
|
||||
}
|
||||
else // text appended, not replaced
|
||||
{
|
||||
// refresh only the new text
|
||||
widthNewText = GetTextWidth(text);
|
||||
}
|
||||
|
||||
m_value = valueNew;
|
||||
|
||||
// force m_colLastVisible update
|
||||
m_colLastVisible = -1;
|
||||
|
||||
// repaint
|
||||
RefreshPixelRange(0, startNewText, widthNewText);
|
||||
}
|
||||
else // multiline
|
||||
{
|
||||
/*
|
||||
Join all the lines in the replacement range into one string, then
|
||||
replace a part of it with the new text and break it into lines again.
|
||||
@@ -598,6 +640,7 @@ void wxTextCtrl::Replace(long from, long to, const wxString& text)
|
||||
|
||||
// update the (cached) last position
|
||||
m_posLast += text.length() - to + from;
|
||||
}
|
||||
|
||||
// update the current position: note that we always put the cursor at the
|
||||
// end of the replacement text
|
||||
|
Reference in New Issue
Block a user