27 #include <wx/stc/stc.h> 30 #include <wx/clipbrd.h> 31 #include <wx/settings.h> 40 m_te->SetScrollWidth( 1 );
41 m_te->SetScrollWidthTracking(
true );
44 wxColour highlight = wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHT );
45 wxColour highlightText = wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWTEXT );
47 unsigned char r = highlight.Red();
48 unsigned char g = highlight.Green();
49 unsigned char b = highlight.Blue();
50 wxColour::MakeGrey( &r, &g, &b );
51 highlight.Set( r, g, b );
53 m_te->StyleSetForeground( wxSTC_STYLE_BRACELIGHT, highlightText );
54 m_te->StyleSetBackground( wxSTC_STYLE_BRACELIGHT, highlight );
55 m_te->StyleSetForeground( wxSTC_STYLE_BRACEBAD, *wxRED );
58 m_te->AutoCompSetIgnoreCase(
true );
60 m_te->AutoCompSetMaxHeight( 20 );
72 if( !aEvent.ControlDown() || aEvent.MetaDown() )
75 if( aEvent.GetUnicodeKey() ==
'/' )
93 if( aEvent.ShiftDown() && ( aEvent.GetUnicodeKey() ==
'7' || aEvent.GetUnicodeKey() ==
':' ) )
106 wxString c = aEvent.GetUnicodeKey();
112 else if( aEvent.GetKeyCode() == WXK_TAB )
114 if( aEvent.ControlDown() )
118 if( !aEvent.ShiftDown() )
119 flags |= wxNavigationKeyEvent::IsForward;
121 wxWindow* parent =
m_te->GetParent();
123 while( parent && dynamic_cast<DIALOG_SHIM*>( parent ) ==
nullptr )
124 parent = parent->GetParent();
127 parent->NavigateIn( flags );
134 else if( aEvent.GetModifiers() == wxMOD_CONTROL && aEvent.GetKeyCode() ==
'Z' )
138 else if( ( aEvent.GetModifiers() == wxMOD_SHIFT+wxMOD_CONTROL && aEvent.GetKeyCode() ==
'Z' )
139 || ( aEvent.GetModifiers() == wxMOD_CONTROL && aEvent.GetKeyCode() ==
'Y' ) )
143 else if( aEvent.GetModifiers() == wxMOD_CONTROL && aEvent.GetKeyCode() ==
'A' )
147 else if( aEvent.GetModifiers() == wxMOD_CONTROL && aEvent.GetKeyCode() ==
'X' )
151 else if( aEvent.GetModifiers() == wxMOD_CONTROL && aEvent.GetKeyCode() ==
'C' )
155 else if( aEvent.GetModifiers() == wxMOD_CONTROL && aEvent.GetKeyCode() ==
'V' )
157 if(
m_te->GetSelectionEnd() >
m_te->GetSelectionStart() )
160 if( wxTheClipboard->Open() )
162 if( wxTheClipboard->IsSupported( wxDF_TEXT ) )
164 wxTextDataObject data;
167 wxTheClipboard->GetData( data );
168 str = data.GetText();
171 m_te->AddText( str );
174 wxTheClipboard->Close();
177 else if( aEvent.GetKeyCode() == WXK_BACK )
181 else if( aEvent.GetKeyCode() == WXK_DELETE )
183 if(
m_te->GetSelectionEnd() >
m_te->GetSelectionStart() )
186 m_te->DeleteRange(
m_te->GetSelectionStart(), 1 );
190 int startLine =
m_te->LineFromPosition(
m_te->GetSelectionStart() );
191 int endLine =
m_te->LineFromPosition(
m_te->GetSelectionEnd() );
195 m_te->BeginUndoAction();
197 for(
int ii = startLine; ii <= endLine; ++ii )
200 m_te->InsertText(
m_te->PositionFromLine( ii ),
"#" );
202 m_te->DeleteRange(
m_te->PositionFromLine( ii ) + whitespaceCount, 1 );
205 m_te->SetSelection(
m_te->PositionFromLine( startLine ),
206 m_te->PositionFromLine( endLine ) +
m_te->GetLineLength( endLine ) );
208 m_te->EndUndoAction();
219 int lineStart =
m_te->PositionFromLine( aLine );
221 if( aWhitespaceCharCount )
222 *aWhitespaceCharCount = 0;
224 for(
int ii = 0; ii <
m_te->GetLineLength( aLine ); ++ii )
226 int c =
m_te->GetCharAt( lineStart + ii );
228 if( c ==
' ' || c ==
'\t' )
230 if( aWhitespaceCharCount )
231 *aWhitespaceCharCount += 1;
247 auto isBrace = [
this](
int c ) ->
bool 249 return m_braces.Find( (wxChar) c ) >= 0;
253 int caretPos =
m_te->GetCurrentPos();
262 if( caretPos > 0 && isBrace(
m_te->GetCharAt( caretPos-1 ) ) )
263 bracePos1 = ( caretPos - 1 );
264 else if( isBrace(
m_te->GetCharAt( caretPos ) ) )
265 bracePos1 = caretPos;
270 bracePos2 =
m_te->BraceMatch( bracePos1 );
272 if( bracePos2 == -1 )
274 m_te->BraceBadLight( bracePos1 );
275 m_te->SetHighlightGuide( 0 );
279 m_te->BraceHighlight( bracePos1, bracePos2 );
280 m_te->SetHighlightGuide(
m_te->GetColumn( bracePos1 ) );
286 m_te->BraceHighlight( -1, -1 );
287 m_te->SetHighlightGuide( 0 );
295 wxArrayString matchedTokens;
297 wxString filter = wxT(
"*" ) + aPartial.Lower() + wxT(
"*" );
299 for(
const wxString& token : aTokens )
301 if( token.Lower().Matches( filter ) )
302 matchedTokens.push_back( token );
305 if( matchedTokens.size() > 0 )
309 matchedTokens.Sort( [](
const wxString& first,
const wxString& second ) ->
int 311 return first.CmpNoCase( second );
314 m_te->AutoCompShow( aPartial.size(), wxJoin( matchedTokens,
' ' ) );
void onCharHook(wxKeyEvent &aEvent)
bool isCtrlSlash(wxKeyEvent &aEvent)
int firstNonWhitespace(int aLine, int *aWhitespaceCount=nullptr)
void DoAutocomplete(const wxString &aPartial, const wxArrayString &aTokens)
SCINTILLA_TRICKS(wxStyledTextCtrl *aScintilla, const wxString &aBraces)
void onScintillaUpdateUI(wxStyledTextEvent &aEvent)
bool ConvertSmartQuotesAndDashes(wxString *aString)
Converts curly quotes and em/en dashes to straight quotes and dashes.