42 std::function<
void( wxKeyEvent& )> onAcceptFn,
43 std::function<
void( wxStyledTextEvent& )> onCharAddedFn ) :
55 m_te->SetEOLMode( wxSTC_EOL_LF );
59 m_te->SetScrollWidth( 1 );
60 m_te->SetScrollWidthTracking(
true );
64 m_te->SetUseVerticalScrollBar(
false );
65 m_te->SetUseHorizontalScrollBar(
false );
71 m_te->AutoCompSetIgnoreCase(
true );
72 m_te->AutoCompSetMaxHeight( 20 );
74 if( aBraces.Length() >= 2 )
88 m_te->Bind( wxEVT_SYS_COLOUR_CHANGED,
103 wxTextCtrl
dummy(
m_te->GetParent(), wxID_ANY );
106 KIGFX::COLOR4D highlight = wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHT );
107 KIGFX::COLOR4D highlightText = wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHTTEXT );
109 m_te->StyleSetForeground( wxSTC_STYLE_DEFAULT, foreground.
ToColour() );
110 m_te->StyleSetBackground( wxSTC_STYLE_DEFAULT, background.
ToColour() );
111 m_te->StyleClearAll();
115 highlight = highlight.
Mix( background, highlight.
a ).
WithAlpha( 1.0 );
116 highlightText = highlightText.
Mix( background, highlightText.
a ).
WithAlpha( 1.0 );
118 m_te->SetSelForeground(
true, highlightText.
ToColour() );
128 for(
size_t i = 0; i < wxSTC_STYLE_MAX; ++i )
129 m_te->StyleSetFont( i, fixedFont );
131 m_te->SetTabWidth( 4 );
139 m_te->StyleSetForeground( wxSTC_STYLE_BRACELIGHT, highlightText.
ToColour() );
140 m_te->StyleSetBackground( wxSTC_STYLE_BRACELIGHT, braceHighlight.
ToColour() );
141 m_te->StyleSetForeground( wxSTC_STYLE_BRACEBAD, *wxRED );
253 auto findGridTricks =
256 wxWindow* parent =
m_te->GetParent();
258 while( parent && !
dynamic_cast<WX_GRID*
>( parent ) )
259 parent = parent->GetParent();
263 wxEvtHandler* handler =
grid->GetEventHandler();
265 while( handler && !
dynamic_cast<GRID_TRICKS*
>( handler ) )
266 handler = handler->GetNextHandler();
275 wxString c = aEvent.GetUnicodeKey();
277 if(
m_te->AutoCompActive() )
279 if( aEvent.GetKeyCode() == WXK_ESCAPE )
281 m_te->AutoCompCancel();
284 else if( aEvent.GetKeyCode() == WXK_RETURN || aEvent.GetKeyCode() == WXK_NUMPAD_ENTER )
286 int start =
m_te->AutoCompPosStart();
288 m_te->AutoCompComplete();
290 int finish =
m_te->GetCurrentPos();
296 int selStart =
m_te->FindText( finish, start,
"<" );
297 int selEnd =
m_te->FindText( finish, start,
">" );
299 if( selStart > start && selEnd <= finish && selEnd > selStart )
300 m_te->SetSelection( selStart, selEnd + 1 );
312 if( aEvent.GetModifiers() == wxMOD_RAW_CONTROL && aEvent.GetKeyCode() == WXK_SPACE )
314 if( aEvent.GetModifiers() == wxMOD_CONTROL && aEvent.GetKeyCode() == WXK_SPACE )
319 wxStyledTextEvent event;
321 event.SetModifiers( wxMOD_CONTROL );
327 if( !isalpha( aEvent.GetKeyCode() ) )
330 if( ( aEvent.GetKeyCode() == WXK_RETURN || aEvent.GetKeyCode() == WXK_NUMPAD_ENTER )
339 else if( aEvent.GetKeyCode() == WXK_TAB )
341 wxWindow* ancestor =
m_te->GetParent();
343 while( ancestor && !
dynamic_cast<WX_GRID*
>( ancestor ) )
344 ancestor = ancestor->GetParent();
346 if( aEvent.ControlDown() )
350 if( !aEvent.ShiftDown() )
351 flags |= wxNavigationKeyEvent::IsForward;
354 dlg->NavigateIn( flags );
356 else if(
dynamic_cast<WX_GRID*
>( ancestor ) )
359 int row =
grid->GetGridCursorRow();
360 int col =
grid->GetGridCursorCol();
362 if( aEvent.ShiftDown() )
370 col = (int)
grid->GetNumberCols() - 1;
376 if( col < (
int)
grid->GetNumberCols() - 1 )
380 else if( row < grid->GetNumberRows() - 1 )
387 grid->SetGridCursor( row, col );
394 else if( aEvent.GetModifiers() == wxMOD_CONTROL && aEvent.GetKeyCode() ==
'Z' )
398 else if( ( aEvent.GetModifiers() == wxMOD_SHIFT+wxMOD_CONTROL && aEvent.GetKeyCode() ==
'Z' )
399 || ( aEvent.GetModifiers() == wxMOD_CONTROL && aEvent.GetKeyCode() ==
'Y' ) )
403 else if( aEvent.GetModifiers() == wxMOD_CONTROL && aEvent.GetKeyCode() ==
'A' )
407 else if( aEvent.GetModifiers() == wxMOD_CONTROL && aEvent.GetKeyCode() ==
'X' )
411 if( wxTheClipboard->Open() )
413 wxTheClipboard->Flush();
414 wxTheClipboard->Close();
417 else if( aEvent.GetModifiers() == wxMOD_CONTROL && aEvent.GetKeyCode() ==
'C' )
421 if( wxTheClipboard->Open() )
423 wxTheClipboard->Flush();
424 wxTheClipboard->Close();
427 else if( aEvent.GetModifiers() == wxMOD_CONTROL && aEvent.GetKeyCode() ==
'V' )
429 if(
m_te->GetSelectionEnd() >
m_te->GetSelectionStart() )
435 if( wxTheClipboard->Open() )
437 if( wxTheClipboard->IsSupported( wxDF_TEXT ) ||
438 wxTheClipboard->IsSupported( wxDF_UNICODETEXT ) )
440 wxTextDataObject data;
443 wxTheClipboard->GetData( data );
444 str = data.GetText();
446 if( str.Contains(
'\t' ) )
447 gridTricks = findGridTricks();
455 str.Replace( wxS(
"\n" ), wxEmptyString );
456 str.Replace( wxS(
"\r" ), wxEmptyString );
459 m_te->BeginUndoAction();
460 m_te->AddText( str );
461 m_te->EndUndoAction();
465 wxTheClipboard->Close();
471 else if( aEvent.GetKeyCode() == WXK_BACK )
473 if( aEvent.GetModifiers() == wxMOD_CONTROL )
476 else if( aEvent.GetModifiers() == wxMOD_ALT )
478 m_te->WordLeftExtend();
482 else if( aEvent.GetKeyCode() == WXK_DELETE )
484 if(
m_te->GetSelectionEnd() ==
m_te->GetSelectionStart() )
487 if( aEvent.GetModifiers() == wxMOD_CONTROL )
488 m_te->WordRightExtend();
491 m_te->CharRightExtend();
494 if(
m_te->GetSelectionEnd() >
m_te->GetSelectionStart() )
499 int startLine =
m_te->LineFromPosition(
m_te->GetSelectionStart() );
500 int endLine =
m_te->LineFromPosition(
m_te->GetSelectionEnd() );
504 m_te->BeginUndoAction();
506 for(
int ii = startLine; ii <= endLine; ++ii )
509 m_te->InsertText(
m_te->PositionFromLine( ii ), wxT(
"#" ) );
511 m_te->DeleteRange(
m_te->PositionFromLine( ii ) + whitespaceCount, 1 );
514 m_te->SetSelection(
m_te->PositionFromLine( startLine ),
515 m_te->PositionFromLine( endLine ) +
m_te->GetLineLength( endLine ) );
517 m_te->EndUndoAction();
520 else if( aEvent.GetModifiers() == wxMOD_RAW_CONTROL && aEvent.GetKeyCode() ==
'A' )
524 else if( aEvent.GetModifiers() == wxMOD_RAW_CONTROL && aEvent.GetKeyCode() ==
'E' )
528 else if( ( aEvent.GetModifiers() & wxMOD_RAW_CONTROL ) && aEvent.GetKeyCode() ==
'B' )
530 if( aEvent.GetModifiers() & wxMOD_ALT )
535 else if( ( aEvent.GetModifiers() & wxMOD_RAW_CONTROL ) && aEvent.GetKeyCode() ==
'F' )
537 if( aEvent.GetModifiers() & wxMOD_ALT )
542 else if( aEvent.GetModifiers() == wxMOD_RAW_CONTROL && aEvent.GetKeyCode() ==
'D' )
544 if(
m_te->GetSelectionEnd() ==
m_te->GetSelectionStart() )
545 m_te->CharRightExtend();
547 if(
m_te->GetSelectionEnd() >
m_te->GetSelectionStart() )
551 else if( aEvent.GetKeyCode() == WXK_SPECIAL20 )
594 [
this](
int c ) ->
bool
596 return m_braces.Find( (wxChar) c ) >= 0;
600 int caretPos =
m_te->GetCurrentPos();
601 int selStart =
m_te->GetSelectionStart();
602 int selEnd =
m_te->GetSelectionEnd();
613 if( caretPos > 0 && isBrace(
m_te->GetCharAt( caretPos-1 ) ) )
614 bracePos1 = ( caretPos - 1 );
615 else if( isBrace(
m_te->GetCharAt( caretPos ) ) )
616 bracePos1 = caretPos;
621 bracePos2 =
m_te->BraceMatch( bracePos1 );
623 if( bracePos2 == -1 )
625 m_te->BraceBadLight( bracePos1 );
626 m_te->SetHighlightGuide( 0 );
630 m_te->BraceHighlight( bracePos1, bracePos2 );
631 m_te->SetHighlightGuide(
m_te->GetColumn( bracePos1 ) );
637 m_te->BraceHighlight( -1, -1 );
638 m_te->SetHighlightGuide( 0 );
645 wxArrayString* tokens )>& getTokensFn )
647 wxArrayString autocompleteTokens;
648 int text_pos =
m_te->GetCurrentPos();
649 int start =
m_te->WordStartPosition( text_pos,
true );
655 return pos >= 2 &&
m_te->GetCharAt( pos-2 ) ==
'$'
656 &&
m_te->GetCharAt( pos-1 ) ==
'{';
660 if( start > 1 &&
m_te->GetCharAt( start-1 ) ==
':' )
662 int refStart =
m_te->WordStartPosition( start-1,
true );
664 if( textVarRef( refStart ) )
666 partial =
m_te->GetRange( start, text_pos );
667 getTokensFn(
m_te->GetRange( refStart, start-1 ), &autocompleteTokens );
670 else if( textVarRef( start ) )
672 partial =
m_te->GetTextRange( start, text_pos );
673 getTokensFn( wxEmptyString, &autocompleteTokens );