diff --git a/common/scintilla_tricks.cpp b/common/scintilla_tricks.cpp index d915b581f3..ebc61bf9b5 100644 --- a/common/scintilla_tricks.cpp +++ b/common/scintilla_tricks.cpp @@ -29,11 +29,13 @@ #include #include #include +#include SCINTILLA_TRICKS::SCINTILLA_TRICKS( wxStyledTextCtrl* aScintilla, const wxString& aBraces ) : m_te( aScintilla ), m_braces( aBraces ), - m_lastCaretPos( -1 ) + m_lastCaretPos( -1 ), + m_suppressAutocomplete( false ) { // A hack which causes Scintilla to auto-size the text editor canvas // See: https://github.com/jacobslusser/ScintillaNET/issues/216 @@ -105,6 +107,9 @@ void SCINTILLA_TRICKS::onCharHook( wxKeyEvent& aEvent ) { wxString c = aEvent.GetUnicodeKey(); + if( !isalpha( aEvent.GetKeyCode() ) ) + m_suppressAutocomplete = false; + if( ConvertSmartQuotesAndDashes( &c ) ) { m_te->AddText( c ); @@ -185,6 +190,18 @@ void SCINTILLA_TRICKS::onCharHook( wxKeyEvent& aEvent ) else m_te->DeleteRange( m_te->GetSelectionStart(), 1 ); } + else if( aEvent.GetKeyCode() == WXK_ESCAPE ) + { + if( m_te->AutoCompActive() ) + { + m_te->AutoCompCancel(); + m_suppressAutocomplete = true; // Don't run autocomplete again on the next char... + } + else if( IsOK( m_te->GetParent(), _( "Cancel changes?" ) ) ) + { + aEvent.Skip(); + } + } else if( isCtrlSlash( aEvent ) ) { int startLine = m_te->LineFromPosition( m_te->GetSelectionStart() ); @@ -292,6 +309,9 @@ void SCINTILLA_TRICKS::onScintillaUpdateUI( wxStyledTextEvent& aEvent ) void SCINTILLA_TRICKS::DoAutocomplete( const wxString& aPartial, const wxArrayString& aTokens ) { + if( m_suppressAutocomplete ) + return; + wxArrayString matchedTokens; wxString filter = wxT( "*" ) + aPartial.Lower() + wxT( "*" ); diff --git a/include/scintilla_tricks.h b/include/scintilla_tricks.h index eaecd282cf..038835eafe 100644 --- a/include/scintilla_tricks.h +++ b/include/scintilla_tricks.h @@ -49,6 +49,7 @@ protected: wxString m_braces; int m_lastCaretPos; + bool m_suppressAutocomplete; }; #endif // SCINTILLA_TRICKS_H diff --git a/pcbnew/dialogs/panel_setup_rules.cpp b/pcbnew/dialogs/panel_setup_rules.cpp index 9c4e1bc15a..ff7ecdcf40 100644 --- a/pcbnew/dialogs/panel_setup_rules.cpp +++ b/pcbnew/dialogs/panel_setup_rules.cpp @@ -319,7 +319,7 @@ void PANEL_SETUP_RULES::onScintillaCharAdded( wxStyledTextEvent &aEvent ) } if( !tokens.IsEmpty() ) - m_scintillaTricks->DoAutocomplete( partial, wxSplit( tokens, ' ' ) ); + m_scintillaTricks-> DoAutocomplete( partial, wxSplit( tokens, ' ' ) ); }