Fix Backspace in wxTextCtrl with custom autocompleter in wxMSW
Pressing Backspace in controls with custom autocompleter previously didn't do anything at all, as it didn't work correctly after backspacing over the just inserted autocompletion, but this was clearly wrong, as it didn't update the list of available completions even after erasing some non-autocompleted characters. Fix this by handling Backspace as any other key and just avoiding refreshing the control contents needlessly if the completion prefix didn't change. Closes #18503.
This commit is contained in:
@@ -160,16 +160,21 @@ public:
|
||||
m_completer = completer;
|
||||
}
|
||||
|
||||
void UpdatePrefix(const wxString& prefix)
|
||||
bool UpdatePrefix(const wxString& prefix)
|
||||
{
|
||||
CSLock lock(m_csRestart);
|
||||
|
||||
if ( prefix == m_prefix )
|
||||
return false;
|
||||
|
||||
// We simply store the prefix here and will really update during the
|
||||
// next call to our Next() method as we want to call Start() from the
|
||||
// worker thread to prevent the main UI thread from blocking while the
|
||||
// completions are generated.
|
||||
m_prefix = prefix;
|
||||
m_restart = TRUE;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual HRESULT STDMETHODCALLTYPE Next(ULONG celt,
|
||||
@@ -557,18 +562,16 @@ private:
|
||||
|
||||
const wxString prefix = m_entry->GetRange(0, from);
|
||||
|
||||
m_enumStrings->UpdatePrefix(prefix);
|
||||
|
||||
if ( m_enumStrings->UpdatePrefix(prefix) )
|
||||
DoRefresh();
|
||||
}
|
||||
|
||||
void OnAfterChar(wxKeyEvent& event)
|
||||
{
|
||||
// Notice that we must not refresh the completions when the user
|
||||
// presses Backspace as this would result in adding back the just
|
||||
// erased character(s) because of ACO_AUTOAPPEND option we use.
|
||||
if ( m_customCompleter && event.GetKeyCode() != WXK_BACK )
|
||||
if ( m_customCompleter )
|
||||
{
|
||||
UpdateStringsFromCustomCompleter();
|
||||
}
|
||||
|
||||
event.Skip();
|
||||
}
|
||||
|
Reference in New Issue
Block a user