From 8a27b2e6bf57d89ed19d1cb5b3e3304081f72ea5 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 15 Sep 2019 23:07:42 +0200 Subject: [PATCH] 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. --- src/msw/textentry.cpp | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/msw/textentry.cpp b/src/msw/textentry.cpp index efe6c4fdd8..0571aa0f70 100644 --- a/src/msw/textentry.cpp +++ b/src/msw/textentry.cpp @@ -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); - - DoRefresh(); + 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(); }