Don't cancel dialog when esc-ing out of autocomplete.

This commit is contained in:
Jeff Young 2021-01-23 22:12:25 +00:00
parent d1c604e699
commit d5d9372839
3 changed files with 23 additions and 2 deletions

View File

@ -29,11 +29,13 @@
#include <dialog_shim.h>
#include <wx/clipbrd.h>
#include <wx/settings.h>
#include <confirm.h>
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( "*" );

View File

@ -49,6 +49,7 @@ protected:
wxString m_braces;
int m_lastCaretPos;
bool m_suppressAutocomplete;
};
#endif // SCINTILLA_TRICKS_H

View File

@ -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, ' ' ) );
}