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:
Vadim Zeitlin
2019-09-15 23:07:42 +02:00
parent 0146c47a7f
commit 8a27b2e6bf

View File

@@ -160,16 +160,21 @@ public:
m_completer = completer; m_completer = completer;
} }
void UpdatePrefix(const wxString& prefix) bool UpdatePrefix(const wxString& prefix)
{ {
CSLock lock(m_csRestart); CSLock lock(m_csRestart);
if ( prefix == m_prefix )
return false;
// We simply store the prefix here and will really update during the // 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 // 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 // worker thread to prevent the main UI thread from blocking while the
// completions are generated. // completions are generated.
m_prefix = prefix; m_prefix = prefix;
m_restart = TRUE; m_restart = TRUE;
return true;
} }
virtual HRESULT STDMETHODCALLTYPE Next(ULONG celt, virtual HRESULT STDMETHODCALLTYPE Next(ULONG celt,
@@ -557,18 +562,16 @@ private:
const wxString prefix = m_entry->GetRange(0, from); const wxString prefix = m_entry->GetRange(0, from);
m_enumStrings->UpdatePrefix(prefix); if ( m_enumStrings->UpdatePrefix(prefix) )
DoRefresh();
DoRefresh();
} }
void OnAfterChar(wxKeyEvent& event) void OnAfterChar(wxKeyEvent& event)
{ {
// Notice that we must not refresh the completions when the user if ( m_customCompleter )
// 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 )
UpdateStringsFromCustomCompleter(); UpdateStringsFromCustomCompleter();
}
event.Skip(); event.Skip();
} }