Differentiate aSingleLine mode for SCINTILLA_TRICKS
This allows us to avoid the monospaced font (along with the tab-stop handling), and process a <return> as an OK rather than just <shift> + <return>. Fixes https://gitlab.com/kicad/code/kicad/issues/8425
This commit is contained in:
parent
062c4fda62
commit
d296bec5b8
|
@ -32,17 +32,22 @@
|
|||
#include <wx/settings.h>
|
||||
#include <confirm.h>
|
||||
|
||||
SCINTILLA_TRICKS::SCINTILLA_TRICKS( wxStyledTextCtrl* aScintilla, const wxString& aBraces ) :
|
||||
SCINTILLA_TRICKS::SCINTILLA_TRICKS( wxStyledTextCtrl* aScintilla, const wxString& aBraces,
|
||||
bool aSingleLine, std::function<void()> 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 );
|
||||
|
||||
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();
|
||||
|
@ -59,6 +64,7 @@ SCINTILLA_TRICKS::SCINTILLA_TRICKS( wxStyledTextCtrl* aScintilla, const wxString
|
|||
|
||||
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 );
|
||||
}
|
||||
|
|
|
@ -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() )
|
||||
{
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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<void()> m_enterCallback = [](){ } );
|
||||
|
||||
void DoAutocomplete( const wxString& aPartial, const wxArrayString& aTokens );
|
||||
|
||||
|
@ -47,9 +48,12 @@ protected:
|
|||
protected:
|
||||
wxStyledTextCtrl* m_te;
|
||||
wxString m_braces;
|
||||
|
||||
int m_lastCaretPos;
|
||||
bool m_suppressAutocomplete;
|
||||
bool m_singleLine; // Treat <return> as OK, and skip special tab
|
||||
// stop handling (including monospaced font).
|
||||
std::function<void()> m_returnCallback; // Process <return> in singleLine, and
|
||||
// <shift> + <return> irrespective.
|
||||
};
|
||||
|
||||
#endif // SCINTILLA_TRICKS_H
|
||||
|
|
|
@ -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 );
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 );
|
||||
|
|
Loading…
Reference in New Issue