From d296bec5b8cd31b634fe4a8a8207f688928d4f09 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Mon, 28 Jun 2021 11:19:12 +0100 Subject: [PATCH] Differentiate aSingleLine mode for SCINTILLA_TRICKS This allows us to avoid the monospaced font (along with the tab-stop handling), and process a as an OK rather than just + . Fixes https://gitlab.com/kicad/code/kicad/issues/8425 --- common/scintilla_tricks.cpp | 42 ++++++++++++------- eeschema/dialogs/dialog_edit_label.cpp | 6 ++- eeschema/dialogs/dialog_edit_one_field.cpp | 6 ++- include/scintilla_tricks.h | 16 ++++--- .../dialogs/properties_frame.cpp | 2 +- pcbnew/dialogs/dialog_text_properties.cpp | 6 ++- pcbnew/dialogs/panel_setup_rules.cpp | 6 ++- 7 files changed, 57 insertions(+), 27 deletions(-) diff --git a/common/scintilla_tricks.cpp b/common/scintilla_tricks.cpp index 56776cd45d..8633c45134 100644 --- a/common/scintilla_tricks.cpp +++ b/common/scintilla_tricks.cpp @@ -32,33 +32,39 @@ #include #include -SCINTILLA_TRICKS::SCINTILLA_TRICKS( wxStyledTextCtrl* aScintilla, const wxString& aBraces ) : +SCINTILLA_TRICKS::SCINTILLA_TRICKS( wxStyledTextCtrl* aScintilla, const wxString& aBraces, + bool aSingleLine, std::function aReturnCallback ) : m_te( aScintilla ), m_braces( aBraces ), m_lastCaretPos( -1 ), - m_suppressAutocomplete( false ) + m_suppressAutocomplete( false ), + m_singleLine( aSingleLine ), + m_returnCallback( aReturnCallback ) { // A hack which causes Scintilla to auto-size the text editor canvas // See: https://github.com/jacobslusser/ScintillaNET/issues/216 m_te->SetScrollWidth( 1 ); m_te->SetScrollWidthTracking( true ); - // Set a monospace font with a tab width of 4. This is the closest we can get to having - // Scintilla mimic the stroke font's tab positioning. - int size = wxNORMAL_FONT->GetPointSize(); - wxFont fixedFont( size, wxFONTFAMILY_TELETYPE, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL ); + if( !m_singleLine ) + { + // Set a monospace font with a tab width of 4. This is the closest we can get to having + // Scintilla mimic the stroke font's tab positioning. + int size = wxNORMAL_FONT->GetPointSize(); + wxFont fixedFont( size, wxFONTFAMILY_TELETYPE, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL ); -#ifdef __WXMAC__ - // I think wxFONTFAMILY_TELETYPE worked on wxWidgets 3.0, but it doesn't on 3.1. Set a - // monospaced font by hand. (https://trac.wxwidgets.org/ticket/19210) - fixedFont.SetFaceName( "Menlo" ); -#endif + #ifdef __WXMAC__ + // I think wxFONTFAMILY_TELETYPE worked on wxWidgets 3.0, but it doesn't on 3.1. Set a + // monospaced font by hand. (https://trac.wxwidgets.org/ticket/19210) + fixedFont.SetFaceName( "Menlo" ); + #endif - for( size_t i = 0; i < wxSTC_STYLE_MAX; ++i ) - m_te->StyleSetFont( i, fixedFont ); + for( size_t i = 0; i < wxSTC_STYLE_MAX; ++i ) + m_te->StyleSetFont( i, fixedFont ); - m_te->StyleClearAll(); // Addresses a bug in wx3.0 where styles are not correctly set - m_te->SetTabWidth( 4 ); + m_te->StyleClearAll(); // Addresses a bug in wx3.0 where styles are not correctly set + m_te->SetTabWidth( 4 ); + } // Set up the brace highlighting wxColour highlight = wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHT ); @@ -128,7 +134,11 @@ void SCINTILLA_TRICKS::onCharHook( wxKeyEvent& aEvent ) if( !isalpha( aEvent.GetKeyCode() ) ) m_suppressAutocomplete = false; - if( ConvertSmartQuotesAndDashes( &c ) ) + if( aEvent.GetKeyCode() == WXK_RETURN && ( m_singleLine || aEvent.ShiftDown() ) ) + { + m_returnCallback(); + } + else if( ConvertSmartQuotesAndDashes( &c ) ) { m_te->AddText( c ); } diff --git a/eeschema/dialogs/dialog_edit_label.cpp b/eeschema/dialogs/dialog_edit_label.cpp index e8daed67f3..b237ab2700 100644 --- a/eeschema/dialogs/dialog_edit_label.cpp +++ b/eeschema/dialogs/dialog_edit_label.cpp @@ -55,7 +55,11 @@ DIALOG_LABEL_EDITOR::DIALOG_LABEL_EDITOR( SCH_EDIT_FRAME* aParent, SCH_TEXT* aTe m_valueMultiLine->SetEOLMode( wxSTC_EOL_LF ); - m_scintillaTricks = new SCINTILLA_TRICKS( m_valueMultiLine, wxT( "{}" ) ); + m_scintillaTricks = new SCINTILLA_TRICKS( m_valueMultiLine, wxT( "{}" ), false, + [this]() + { + wxPostEvent( this, wxCommandEvent( wxEVT_COMMAND_BUTTON_CLICKED, wxID_OK ) ); + } ); if( m_CurrentText->IsMultilineAllowed() ) { diff --git a/eeschema/dialogs/dialog_edit_one_field.cpp b/eeschema/dialogs/dialog_edit_one_field.cpp index 8be48407f1..a43c25f89f 100644 --- a/eeschema/dialogs/dialog_edit_one_field.cpp +++ b/eeschema/dialogs/dialog_edit_one_field.cpp @@ -57,7 +57,11 @@ DIALOG_EDIT_ONE_FIELD::DIALOG_EDIT_ONE_FIELD( SCH_BASE_FRAME* aParent, const wxS m_fieldId = VALUE_FIELD; m_isPower = false; - m_scintillaTricks = new SCINTILLA_TRICKS( m_StyledTextCtrl, wxT( "{}" ) ); + m_scintillaTricks = new SCINTILLA_TRICKS( m_StyledTextCtrl, wxT( "{}" ), true, + [this]() + { + wxPostEvent( this, wxCommandEvent( wxEVT_COMMAND_BUTTON_CLICKED, wxID_OK ) ); + } ); m_StyledTextCtrl->SetEOLMode( wxSTC_EOL_LF ); // Normalize EOL across platforms m_text = aTextItem->GetText(); diff --git a/include/scintilla_tricks.h b/include/scintilla_tricks.h index 038835eafe..01685fc9e8 100644 --- a/include/scintilla_tricks.h +++ b/include/scintilla_tricks.h @@ -34,7 +34,8 @@ class SCINTILLA_TRICKS : public wxEvtHandler { public: - SCINTILLA_TRICKS( wxStyledTextCtrl* aScintilla, const wxString& aBraces ); + SCINTILLA_TRICKS( wxStyledTextCtrl* aScintilla, const wxString& aBraces, bool aSingleLine, + std::function m_enterCallback = [](){ } ); void DoAutocomplete( const wxString& aPartial, const wxArrayString& aTokens ); @@ -45,11 +46,14 @@ protected: void onScintillaUpdateUI( wxStyledTextEvent& aEvent ); protected: - wxStyledTextCtrl* m_te; - wxString m_braces; - - int m_lastCaretPos; - bool m_suppressAutocomplete; + wxStyledTextCtrl* m_te; + wxString m_braces; + int m_lastCaretPos; + bool m_suppressAutocomplete; + bool m_singleLine; // Treat as OK, and skip special tab + // stop handling (including monospaced font). + std::function m_returnCallback; // Process in singleLine, and + // + irrespective. }; #endif // SCINTILLA_TRICKS_H diff --git a/pagelayout_editor/dialogs/properties_frame.cpp b/pagelayout_editor/dialogs/properties_frame.cpp index 240f45b7c7..f8d4002a99 100644 --- a/pagelayout_editor/dialogs/properties_frame.cpp +++ b/pagelayout_editor/dialogs/properties_frame.cpp @@ -62,7 +62,7 @@ PROPERTIES_FRAME::PROPERTIES_FRAME( PL_EDITOR_FRAME* aParent ) : m_stcText->SetUseVerticalScrollBar( false ); m_stcText->SetUseHorizontalScrollBar( false ); - m_scintillaTricks = new SCINTILLA_TRICKS( m_stcText, wxT( "{}" ) ); + m_scintillaTricks = new SCINTILLA_TRICKS( m_stcText, wxT( "{}" ), false ); wxFont infoFont = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT ); infoFont.SetSymbolicSize( wxFONTSIZE_X_SMALL ); diff --git a/pcbnew/dialogs/dialog_text_properties.cpp b/pcbnew/dialogs/dialog_text_properties.cpp index f2c9787af5..8a4d29bd40 100644 --- a/pcbnew/dialogs/dialog_text_properties.cpp +++ b/pcbnew/dialogs/dialog_text_properties.cpp @@ -60,7 +60,11 @@ DIALOG_TEXT_PROPERTIES::DIALOG_TEXT_PROPERTIES( PCB_BASE_EDIT_FRAME* aParent, BO m_MultiLineText->SetEOLMode( wxSTC_EOL_LF ); - m_scintillaTricks = new SCINTILLA_TRICKS( m_MultiLineText, wxT( "{}" ) ); + m_scintillaTricks = new SCINTILLA_TRICKS( m_MultiLineText, wxT( "{}" ), false, + [this]() + { + wxPostEvent( this, wxCommandEvent( wxEVT_COMMAND_BUTTON_CLICKED, wxID_OK ) ); + } ); // A hack which causes Scintilla to auto-size the text editor canvas // See: https://github.com/jacobslusser/ScintillaNET/issues/216 diff --git a/pcbnew/dialogs/panel_setup_rules.cpp b/pcbnew/dialogs/panel_setup_rules.cpp index 3ca90a40eb..2b4e8d3892 100644 --- a/pcbnew/dialogs/panel_setup_rules.cpp +++ b/pcbnew/dialogs/panel_setup_rules.cpp @@ -47,7 +47,11 @@ PANEL_SETUP_RULES::PANEL_SETUP_RULES( PAGED_DIALOG* aParent, PCB_EDIT_FRAME* aFr m_scintillaTricks( nullptr ), m_helpWindow( nullptr ) { - m_scintillaTricks = new SCINTILLA_TRICKS( m_textEditor, wxT( "()" ) ); + m_scintillaTricks = new SCINTILLA_TRICKS( m_textEditor, wxT( "()" ), false, + [this]() + { + wxPostEvent( m_Parent, wxCommandEvent( wxEVT_COMMAND_BUTTON_CLICKED, wxID_OK ) ); + } ); m_netClassRegex.Compile( "NetClass\\s*[!=]=\\s*$", wxRE_ADVANCED ); m_netNameRegex.Compile( "NetName\\s*[!=]=\\s*$", wxRE_ADVANCED );