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
|
else
|
||||||
m_te->DeleteRange( m_te->GetSelectionStart(), 1 );
|
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
|
else
|
||||||
{
|
{
|
||||||
aEvent.Skip();
|
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 )
|
void SCINTILLA_TRICKS::onScintillaUpdateUI( wxStyledTextEvent& aEvent )
|
||||||
{
|
{
|
||||||
auto isBrace = [this]( int c ) -> bool
|
auto isBrace = [this]( int c ) -> bool
|
||||||
|
|
|
@ -41,6 +41,8 @@ public:
|
||||||
void DoAutocomplete( const wxString& aPartial, const wxArrayString& aTokens );
|
void DoAutocomplete( const wxString& aPartial, const wxArrayString& aTokens );
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
int firstNonWhitespace( int aLine, int* aWhitespaceCount = nullptr );
|
||||||
|
|
||||||
void onCharHook( wxKeyEvent& aEvent );
|
void onCharHook( wxKeyEvent& aEvent );
|
||||||
void onScintillaUpdateUI( wxStyledTextEvent& aEvent );
|
void onScintillaUpdateUI( wxStyledTextEvent& aEvent );
|
||||||
|
|
||||||
|
|
|
@ -406,9 +406,9 @@ void PANEL_SETUP_RULES::OnSyntaxHelp( wxHyperlinkEvent& aEvent )
|
||||||
msg << _( "Item Types" );
|
msg << _( "Item Types" );
|
||||||
msg << "</b>"
|
msg << "</b>"
|
||||||
"<pre>"
|
"<pre>"
|
||||||
"track via zone\r"
|
"track via zone\r"
|
||||||
"pad micro_via text\r"
|
"pad micro_via text\r"
|
||||||
"hole buried_via graphic\r"
|
"hole buried_via graphic\r"
|
||||||
"\r</pre>"
|
"\r</pre>"
|
||||||
"<b>";
|
"<b>";
|
||||||
msg << _( "Examples" );
|
msg << _( "Examples" );
|
||||||
|
@ -431,6 +431,12 @@ void PANEL_SETUP_RULES::OnSyntaxHelp( wxHyperlinkEvent& aEvent )
|
||||||
" # wider clearance between HV tracks\r"
|
" # wider clearance between HV tracks\r"
|
||||||
" (constraint clearance (min \"1.5mm + 2.0mm\"))\r"
|
" (constraint clearance (min \"1.5mm + 2.0mm\"))\r"
|
||||||
" (condition \"A.netclass == 'HV' && B.netclass == 'HV'\"))\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>";
|
"</pre>";
|
||||||
|
|
||||||
HTML_MESSAGE_BOX* dlg = new HTML_MESSAGE_BOX( nullptr, _( "Syntax Help" ) );
|
HTML_MESSAGE_BOX* dlg = new HTML_MESSAGE_BOX( nullptr, _( "Syntax Help" ) );
|
||||||
|
|
Loading…
Reference in New Issue