Move autocomplete to the remove filtered items paradigm.

Fixes https://gitlab.com/kicad/code/kicad/issues/4190
This commit is contained in:
Jeff Young 2020-05-30 20:00:09 +01:00
parent 9414f65a3f
commit 0741bbb1b9
4 changed files with 26 additions and 16 deletions

View File

@ -50,6 +50,11 @@ SCINTILLA_TRICKS::SCINTILLA_TRICKS( wxStyledTextCtrl* aScintilla, const wxString
m_te->StyleSetBackground( wxSTC_STYLE_BRACELIGHT, highlight );
m_te->StyleSetForeground( wxSTC_STYLE_BRACEBAD, *wxRED );
// Set up autocomplete
m_te->AutoCompSetIgnoreCase( true );
m_te->AutoCompSetFillUps( m_braces[1] );
m_te->AutoCompSetMaxHeight( 20 );
// Hook up events
m_te->Bind( wxEVT_STC_UPDATEUI, &SCINTILLA_TRICKS::onScintillaUpdateUI, this );
@ -180,23 +185,25 @@ void SCINTILLA_TRICKS::onScintillaUpdateUI( wxStyledTextEvent& aEvent )
}
void SCINTILLA_TRICKS::DoAutocomplete( const wxString& aPartial, wxArrayString aTokens )
void SCINTILLA_TRICKS::DoAutocomplete( const wxString& aPartial, const wxArrayString& aTokens )
{
if( aTokens.size() > 0 )
wxArrayString matchedTokens;
wxString filter = wxT( "*" ) + aPartial.Lower() + wxT( "*" );
for( const wxString& token : aTokens )
{
bool match = aPartial.IsEmpty();
if( token.Lower().Matches( filter ) )
matchedTokens.push_back( token );
}
for( size_t ii = 0; ii < aTokens.size() && !match; ++ii )
match = aTokens[ii].StartsWith( aPartial );
if( matchedTokens.size() > 0 )
{
// NB: tokens MUST be in alphabetical order because the Scintilla engine is going
// to do a binary search on them
matchedTokens.Sort();
if( match )
{
// NB: tokens MUST be in alphabetical order because the Scintilla engine is going
// to do a binary search on them
aTokens.Sort();
m_te->AutoCompShow( aPartial.size(), wxJoin( aTokens, ' ' ) );
}
m_te->AutoCompShow( aPartial.size(), wxJoin( matchedTokens, ' ' ) );
}
}

View File

@ -75,7 +75,7 @@ void TEXTENTRY_TRICKS::OnCharHook( wxTextEntry* aTextEntry, wxKeyEvent& aEvent )
long start, end;
aTextEntry->GetSelection( &start, &end );
if( start > end )
if( end > start )
{
aTextEntry->Remove( start, end );
aTextEntry->SetInsertionPoint( start );

View File

@ -37,6 +37,7 @@
#include <wx/log.h>
#include <wx/stc/stc.h>
#include <textentry_tricks.h>
#include <wx/listctrl.h>
using namespace std::placeholders;
@ -386,7 +387,9 @@ void ACTION_MENU::OnMenuEvent( wxMenuEvent& aEvent )
// in TOOL_DISPATCHER::DispatchWxEvent, wxWidgets sometimes converts those it knows
// about into menu commands without ever generating the appropriate CHAR_HOOK and CHAR
// events first.
if( dynamic_cast<wxStyledTextCtrl*>( focus ) || dynamic_cast<wxTextEntry*>( focus ) )
if( dynamic_cast<wxTextEntry*>( focus )
|| dynamic_cast<wxStyledTextCtrl*>( focus )
|| dynamic_cast<wxListView*>( focus ) )
{
// Original key event has been lost, so we have to re-create it from the menu's
// wxAcceleratorEntry.

View File

@ -38,7 +38,7 @@ public:
SCINTILLA_TRICKS( wxStyledTextCtrl* aScintilla, const wxString& aBraces );
void DoAutocomplete( const wxString& aPartial, wxArrayString aTokens );
void DoAutocomplete( const wxString& aPartial, const wxArrayString& aTokens );
protected:
bool isCtrl( int aChar, const wxKeyEvent& e );