Fix Scintilla vertical scrolling issue.

(At least on MacOS.  *May* also fix GTK.)

(cherry picked from commit c5947d89012ce55f490e7d4411bd316396627b63)
This commit is contained in:
Jeff Young 2025-05-28 13:53:43 +01:00 committed by Alex Shvartzkop
parent c5fb2283b6
commit c4fdf9feeb
7 changed files with 21 additions and 11 deletions

View File

@ -111,11 +111,11 @@ wxSize GRID_CELL_ESCAPED_TEXT_RENDERER::GetBestSize( wxGrid & aGrid, wxGridCellA
//-------- GRID_CELL_STC_EDITOR -----------------------------------------------------------------
//
GRID_CELL_STC_EDITOR::GRID_CELL_STC_EDITOR(
bool aIgnoreCase,
std::function<void( wxStyledTextEvent&, SCINTILLA_TRICKS* )> onCharFn ) :
GRID_CELL_STC_EDITOR::GRID_CELL_STC_EDITOR( bool aIgnoreCase, bool aSingleLine,
std::function<void( wxStyledTextEvent&, SCINTILLA_TRICKS* )> onCharFn ) :
m_scintillaTricks( nullptr ),
m_ignoreCase( aIgnoreCase ),
m_singleLine( aSingleLine ),
m_onCharFn( std::move( onCharFn ) )
{ }
@ -132,7 +132,7 @@ void GRID_CELL_STC_EDITOR::SetSize( const wxRect& aRect )
rect.Offset( -1, 3 );
#else
rect.Offset( 1, 3 );
rect.SetHeight( rect.GetHeight() - 6 );
rect.SetHeight( rect.GetHeight() - 4 );
#endif
wxGridCellEditor::SetSize( rect );
}
@ -161,7 +161,7 @@ void GRID_CELL_STC_EDITOR::Create( wxWindow* aParent, wxWindowID aId, wxEvtHandl
stc_ctrl()->SetScrollWidthTracking( true );
m_scintillaTricks = new SCINTILLA_TRICKS(
stc_ctrl(), wxEmptyString, false,
stc_ctrl(), wxEmptyString, m_singleLine,
// onAcceptFn
[this]( wxKeyEvent& aEvent )

View File

@ -79,7 +79,7 @@ DIALOG_TABLE_PROPERTIES::DIALOG_TABLE_PROPERTIES( SCH_EDIT_FRAME* aFrame, SCH_TA
}
else
{
attr->SetEditor( new GRID_CELL_STC_EDITOR( true,
attr->SetEditor( new GRID_CELL_STC_EDITOR( true, false,
// onCharFn
[this]( wxStyledTextEvent& aEvent, SCINTILLA_TRICKS* aScintillaTricks )
{

View File

@ -117,6 +117,11 @@ DIALOG_TEXT_PROPERTIES::DIALOG_TEXT_PROPERTIES( SCH_BASE_FRAME* aParent, SCH_ITE
} );
} );
// A hack which causes Scintilla to auto-size the text editor canvas
// See: https://github.com/jacobslusser/ScintillaNET/issues/216
m_textCtrl->SetScrollWidth( 1 );
m_textCtrl->SetScrollWidthTracking( true );
m_textEntrySizer->AddGrowableRow( 0 );
m_textColorSwatch->SetDefaultColor( COLOR4D::UNSPECIFIED );

View File

@ -40,6 +40,10 @@ DIALOG_USER_DEFINED_SIGNALS::DIALOG_USER_DEFINED_SIGNALS( SIMULATOR_FRAME* aPare
{
m_grid->PushEventHandler( new GRID_TRICKS( m_grid ) );
// Give a little more room for Scintilla text editor (which otherwise likes to scroll
// on every other keystroke).
m_grid->SetDefaultRowSize( m_grid->GetDefaultRowSize() + 4 );
wxGridCellAttr* attr = new wxGridCellAttr;
attr->SetReadOnly();
m_grid->SetColAttr( 1, attr );
@ -93,7 +97,7 @@ void DIALOG_USER_DEFINED_SIGNALS::addGridRow( const wxString& aText, int aId )
// So use a GRID_CELL_TEXT_EDITOR.
attr->SetEditor( new GRID_CELL_TEXT_EDITOR() );
#else
attr->SetEditor( new GRID_CELL_STC_EDITOR( true,
attr->SetEditor( new GRID_CELL_STC_EDITOR( true, true,
[this]( wxStyledTextEvent& aEvent, SCINTILLA_TRICKS* aScintillaTricks )
{
onScintillaCharAdded( aEvent, aScintillaTricks );

View File

@ -253,7 +253,7 @@ void FIELDS_GRID_TABLE::initGrid( WX_GRID* aGrid )
}
else
{
GRID_CELL_STC_EDITOR* valueEditor = new GRID_CELL_STC_EDITOR( true,
GRID_CELL_STC_EDITOR* valueEditor = new GRID_CELL_STC_EDITOR( true, true,
[this]( wxStyledTextEvent& aEvent, SCINTILLA_TRICKS* aScintillaTricks )
{
SCH_FIELD& valueField = static_cast<SCH_FIELD&>( this->at( VALUE_FIELD ) );

View File

@ -69,7 +69,7 @@ public:
class GRID_CELL_STC_EDITOR : public wxGridCellEditor
{
public:
GRID_CELL_STC_EDITOR( bool aIgnoreCase,
GRID_CELL_STC_EDITOR( bool aIgnoreCase, bool aSingleLine,
std::function<void( wxStyledTextEvent&, SCINTILLA_TRICKS* )> onCharFn );
void SetSize( const wxRect& aRect ) override;
@ -77,7 +77,7 @@ public:
wxGridCellEditor* Clone() const override
{
return new GRID_CELL_STC_EDITOR( m_ignoreCase, m_onCharFn );
return new GRID_CELL_STC_EDITOR( m_ignoreCase, m_singleLine, m_onCharFn );
}
wxString GetValue() const override;
@ -97,6 +97,7 @@ protected:
protected:
SCINTILLA_TRICKS* m_scintillaTricks;
bool m_ignoreCase;
bool m_singleLine;
wxString m_value;
std::function<void( wxStyledTextEvent&, SCINTILLA_TRICKS* )> m_onCharFn;

View File

@ -86,7 +86,7 @@ DIALOG_TABLE_PROPERTIES::DIALOG_TABLE_PROPERTIES( PCB_BASE_EDIT_FRAME* aFrame, P
}
else
{
attr->SetEditor( new GRID_CELL_STC_EDITOR( true,
attr->SetEditor( new GRID_CELL_STC_EDITOR( true, false,
[this, cell]( wxStyledTextEvent& aEvent, SCINTILLA_TRICKS* aScintillaTricks )
{
aScintillaTricks->DoTextVarAutocomplete(