diff --git a/common/scintilla_tricks.cpp b/common/scintilla_tricks.cpp index c3468abd37..8c76a0efeb 100644 --- a/common/scintilla_tricks.cpp +++ b/common/scintilla_tricks.cpp @@ -147,6 +147,28 @@ void SCINTILLA_TRICKS::onCharHook( wxKeyEvent& aEvent ) else m_te->DeleteRange( m_te->GetSelectionStart(), 1 ); } + else if( ( aEvent.GetModifiers() == wxMOD_CONTROL && aEvent.GetKeyCode() == '/' ) ) + { + int startLine = m_te->LineFromPosition( m_te->GetSelectionStart() ); + int endLine = m_te->LineFromPosition( m_te->GetSelectionEnd() ); + bool comment = firstNonWhitespace( startLine ) != '#'; + int whitespaceCount; + + m_te->BeginUndoAction(); + + for( int ii = startLine; ii <= endLine; ++ii ) + { + if( comment ) + m_te->InsertText( m_te->PositionFromLine( ii ), "#" ); + else if( firstNonWhitespace( ii, &whitespaceCount ) == '#' ) + m_te->DeleteRange( m_te->PositionFromLine( ii ) + whitespaceCount, 1 ); + } + + m_te->SetSelection( m_te->PositionFromLine( startLine ), + m_te->PositionFromLine( endLine ) + m_te->GetLineLength( endLine ) ); + + m_te->EndUndoAction(); + } else { aEvent.Skip(); @@ -154,6 +176,34 @@ void SCINTILLA_TRICKS::onCharHook( wxKeyEvent& aEvent ) } +int SCINTILLA_TRICKS::firstNonWhitespace( int aLine, int* aWhitespaceCharCount ) +{ + int lineStart = m_te->PositionFromLine( aLine ); + + if( aWhitespaceCharCount ) + *aWhitespaceCharCount = 0; + + for( int ii = 0; ii < m_te->GetLineLength( aLine ); ++ii ) + { + int c = m_te->GetCharAt( lineStart + ii ); + + if( c == ' ' || c == '\t' ) + { + if( aWhitespaceCharCount ) + *aWhitespaceCharCount += 1; + + continue; + } + else + { + return c; + } + } + + return '\r'; +} + + void SCINTILLA_TRICKS::onScintillaUpdateUI( wxStyledTextEvent& aEvent ) { auto isBrace = [this]( int c ) -> bool diff --git a/include/scintilla_tricks.h b/include/scintilla_tricks.h index ef33e7cd9e..97d270993f 100644 --- a/include/scintilla_tricks.h +++ b/include/scintilla_tricks.h @@ -41,6 +41,8 @@ public: void DoAutocomplete( const wxString& aPartial, const wxArrayString& aTokens ); protected: + int firstNonWhitespace( int aLine, int* aWhitespaceCount = nullptr ); + void onCharHook( wxKeyEvent& aEvent ); void onScintillaUpdateUI( wxStyledTextEvent& aEvent ); diff --git a/pcbnew/dialogs/panel_setup_rules.cpp b/pcbnew/dialogs/panel_setup_rules.cpp index 51a8c298e3..69306d0ec3 100644 --- a/pcbnew/dialogs/panel_setup_rules.cpp +++ b/pcbnew/dialogs/panel_setup_rules.cpp @@ -406,9 +406,9 @@ void PANEL_SETUP_RULES::OnSyntaxHelp( wxHyperlinkEvent& aEvent ) msg << _( "Item Types" ); msg << "" "
" - "track via zone\r" - "pad micro_via text\r" - "hole buried_via graphic\r" + "track via zone\r" + "pad micro_via text\r" + "hole buried_via graphic\r" "\r" ""; msg << _( "Examples" ); @@ -431,6 +431,12 @@ void PANEL_SETUP_RULES::OnSyntaxHelp( wxHyperlinkEvent& aEvent ) " # wider clearance between HV tracks\r" " (constraint clearance (min \"1.5mm + 2.0mm\"))\r" " (condition \"A.netclass == 'HV' && B.netclass == 'HV'\"))\r" + "\r" +#ifdef __WXMAC__ + "# Use Cmd+/ to comment or uncomment line(s)\r" +#else + "# Use Ctrl+/ to comment or uncomment line(s)\r" +#endif ""; HTML_MESSAGE_BOX* dlg = new HTML_MESSAGE_BOX( nullptr, _( "Syntax Help" ) );