ADDED hotkey for comment/uncomment line(s) in Scintilla.
Useful primarily for DRC Rules editor. Fixes https://gitlab.com/kicad/code/kicad/issues/5480
This commit is contained in:
parent
555b78e7ca
commit
3573c8b967
|
@ -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
|
||||
|
|
|
@ -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 );
|
||||
|
||||
|
|
|
@ -406,9 +406,9 @@ void PANEL_SETUP_RULES::OnSyntaxHelp( wxHyperlinkEvent& aEvent )
|
|||
msg << _( "Item Types" );
|
||||
msg << "</b>"
|
||||
"<pre>"
|
||||
"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</pre>"
|
||||
"<b>";
|
||||
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
|
||||
"</pre>";
|
||||
|
||||
HTML_MESSAGE_BOX* dlg = new HTML_MESSAGE_BOX( nullptr, _( "Syntax Help" ) );
|
||||
|
|
Loading…
Reference in New Issue