38 std::function<
void( wxKeyEvent& )> onAcceptFn,
39 std::function<
void( wxStyledTextEvent& )> onCharAddedFn ) :
51 m_te->SetEOLMode( wxSTC_EOL_LF );
55 m_te->SetScrollWidth( 1 );
56 m_te->SetScrollWidthTracking(
true );
60 m_te->SetUseVerticalScrollBar(
false );
61 m_te->SetUseHorizontalScrollBar(
false );
67 m_te->AutoCompSetIgnoreCase(
true );
68 m_te->AutoCompSetMaxHeight( 20 );
70 if( aBraces.Length() >= 2 )
84 m_te->Bind( wxEVT_SYS_COLOUR_CHANGED,
99 wxTextCtrl
dummy(
m_te->GetParent(), wxID_ANY );
102 KIGFX::COLOR4D highlight = wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHT );
103 KIGFX::COLOR4D highlightText = wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHTTEXT );
105 m_te->StyleSetForeground( wxSTC_STYLE_DEFAULT, foreground.
ToColour() );
106 m_te->StyleSetBackground( wxSTC_STYLE_DEFAULT, background.
ToColour() );
107 m_te->StyleClearAll();
111 highlight = highlight.
Mix( background, highlight.
a ).
WithAlpha( 1.0 );
112 highlightText = highlightText.
Mix( background, highlightText.
a ).
WithAlpha( 1.0 );
114 m_te->SetSelForeground(
true, highlightText.
ToColour() );
124 for(
size_t i = 0; i < wxSTC_STYLE_MAX; ++i )
125 m_te->StyleSetFont( i, fixedFont );
127 m_te->SetTabWidth( 4 );
135 m_te->StyleSetForeground( wxSTC_STYLE_BRACELIGHT, highlightText.
ToColour() );
136 m_te->StyleSetBackground( wxSTC_STYLE_BRACELIGHT, braceHighlight.
ToColour() );
137 m_te->StyleSetForeground( wxSTC_STYLE_BRACEBAD, *wxRED );
251 auto findGridTricks =
254 wxWindow* parent =
m_te->GetParent();
256 while( parent && !
dynamic_cast<WX_GRID*
>( parent ) )
257 parent = parent->GetParent();
261 wxEvtHandler* handler =
grid->GetEventHandler();
263 while( handler && !
dynamic_cast<GRID_TRICKS*
>( handler ) )
264 handler = handler->GetNextHandler();
273 wxString c = aEvent.GetUnicodeKey();
275 if(
m_te->AutoCompActive() )
277 if( aEvent.GetKeyCode() == WXK_ESCAPE )
279 m_te->AutoCompCancel();
282 else if( aEvent.GetKeyCode() == WXK_RETURN || aEvent.GetKeyCode() == WXK_NUMPAD_ENTER )
284 int start =
m_te->AutoCompPosStart();
286 m_te->AutoCompComplete();
288 int finish =
m_te->GetCurrentPos();
294 int selStart =
m_te->FindText( finish, start,
"<" );
295 int selEnd =
m_te->FindText( finish, start,
">" );
297 if( selStart > start && selEnd <= finish && selEnd > selStart )
298 m_te->SetSelection( selStart, selEnd + 1 );
310 if( aEvent.GetModifiers() == wxMOD_RAW_CONTROL && aEvent.GetKeyCode() == WXK_SPACE )
312 if( aEvent.GetModifiers() == wxMOD_CONTROL && aEvent.GetKeyCode() == WXK_SPACE )
317 wxStyledTextEvent event;
319 event.SetModifiers( wxMOD_CONTROL );
325 if( !isalpha( aEvent.GetKeyCode() ) )
328 if( ( aEvent.GetKeyCode() == WXK_RETURN || aEvent.GetKeyCode() == WXK_NUMPAD_ENTER )
337 else if( aEvent.GetKeyCode() == WXK_TAB )
339 wxWindow* ancestor =
m_te->GetParent();
341 while( ancestor && !
dynamic_cast<WX_GRID*
>( ancestor ) )
342 ancestor = ancestor->GetParent();
344 if( aEvent.ControlDown() )
348 if( !aEvent.ShiftDown() )
349 flags |= wxNavigationKeyEvent::IsForward;
352 dlg->NavigateIn( flags );
354 else if(
dynamic_cast<WX_GRID*
>( ancestor ) )
357 int row =
grid->GetGridCursorRow();
358 int col =
grid->GetGridCursorCol();
360 if( aEvent.ShiftDown() )
368 col = (int)
grid->GetNumberCols() - 1;
374 if( col < (
int)
grid->GetNumberCols() - 1 )
378 else if( row < grid->GetNumberRows() - 1 )
385 grid->SetGridCursor( row, col );
392 else if( aEvent.GetModifiers() == wxMOD_CONTROL && aEvent.GetKeyCode() ==
'Z' )
396 else if( ( aEvent.GetModifiers() == wxMOD_SHIFT+wxMOD_CONTROL && aEvent.GetKeyCode() ==
'Z' )
397 || ( aEvent.GetModifiers() == wxMOD_CONTROL && aEvent.GetKeyCode() ==
'Y' ) )
401 else if( aEvent.GetModifiers() == wxMOD_CONTROL && aEvent.GetKeyCode() ==
'A' )
405 else if( aEvent.GetModifiers() == wxMOD_CONTROL && aEvent.GetKeyCode() ==
'X' )
409 if( wxTheClipboard->Open() )
411 wxTheClipboard->Flush();
412 wxTheClipboard->Close();
415 else if( aEvent.GetModifiers() == wxMOD_CONTROL && aEvent.GetKeyCode() ==
'C' )
419 if( wxTheClipboard->Open() )
421 wxTheClipboard->Flush();
422 wxTheClipboard->Close();
425 else if( aEvent.GetModifiers() == wxMOD_CONTROL && aEvent.GetKeyCode() ==
'V' )
427 if(
m_te->GetSelectionEnd() >
m_te->GetSelectionStart() )
433 if( wxTheClipboard->Open() )
435 if( wxTheClipboard->IsSupported( wxDF_TEXT ) ||
436 wxTheClipboard->IsSupported( wxDF_UNICODETEXT ) )
438 wxTextDataObject data;
441 wxTheClipboard->GetData( data );
442 str = data.GetText();
444 if( str.Contains(
'\t' ) )
445 gridTricks = findGridTricks();
453 str.Replace( wxS(
"\n" ), wxEmptyString );
454 str.Replace( wxS(
"\r" ), wxEmptyString );
457 m_te->BeginUndoAction();
458 m_te->AddText( str );
459 m_te->EndUndoAction();
463 wxTheClipboard->Close();
469 else if( aEvent.GetKeyCode() == WXK_BACK )
471 if( aEvent.GetModifiers() == wxMOD_CONTROL )
474 else if( aEvent.GetModifiers() == wxMOD_ALT )
476 m_te->WordLeftExtend();
480 else if( aEvent.GetKeyCode() == WXK_DELETE )
482 if(
m_te->GetSelectionEnd() ==
m_te->GetSelectionStart() )
485 if( aEvent.GetModifiers() == wxMOD_CONTROL )
486 m_te->WordRightExtend();
489 m_te->CharRightExtend();
492 if(
m_te->GetSelectionEnd() >
m_te->GetSelectionStart() )
497 int startLine =
m_te->LineFromPosition(
m_te->GetSelectionStart() );
498 int endLine =
m_te->LineFromPosition(
m_te->GetSelectionEnd() );
502 m_te->BeginUndoAction();
504 for(
int ii = startLine; ii <= endLine; ++ii )
507 m_te->InsertText(
m_te->PositionFromLine( ii ), wxT(
"#" ) );
509 m_te->DeleteRange(
m_te->PositionFromLine( ii ) + whitespaceCount, 1 );
512 m_te->SetSelection(
m_te->PositionFromLine( startLine ),
513 m_te->PositionFromLine( endLine ) +
m_te->GetLineLength( endLine ) );
515 m_te->EndUndoAction();
518 else if( aEvent.GetModifiers() == wxMOD_RAW_CONTROL && aEvent.GetKeyCode() ==
'A' )
522 else if( aEvent.GetModifiers() == wxMOD_RAW_CONTROL && aEvent.GetKeyCode() ==
'E' )
526 else if( ( aEvent.GetModifiers() & wxMOD_RAW_CONTROL ) && aEvent.GetKeyCode() ==
'B' )
528 if( aEvent.GetModifiers() & wxMOD_ALT )
533 else if( ( aEvent.GetModifiers() & wxMOD_RAW_CONTROL ) && aEvent.GetKeyCode() ==
'F' )
535 if( aEvent.GetModifiers() & wxMOD_ALT )
540 else if( aEvent.GetModifiers() == wxMOD_RAW_CONTROL && aEvent.GetKeyCode() ==
'D' )
542 if(
m_te->GetSelectionEnd() ==
m_te->GetSelectionStart() )
543 m_te->CharRightExtend();
545 if(
m_te->GetSelectionEnd() >
m_te->GetSelectionStart() )
549 else if( aEvent.GetKeyCode() == WXK_SPECIAL20 )
592 [
this](
int c ) ->
bool
594 return m_braces.Find( (wxChar) c ) >= 0;
598 int caretPos =
m_te->GetCurrentPos();
599 int selStart =
m_te->GetSelectionStart();
600 int selEnd =
m_te->GetSelectionEnd();
611 if( caretPos > 0 && isBrace(
m_te->GetCharAt( caretPos-1 ) ) )
612 bracePos1 = ( caretPos - 1 );
613 else if( isBrace(
m_te->GetCharAt( caretPos ) ) )
614 bracePos1 = caretPos;
619 bracePos2 =
m_te->BraceMatch( bracePos1 );
621 if( bracePos2 == -1 )
623 m_te->BraceBadLight( bracePos1 );
624 m_te->SetHighlightGuide( 0 );
628 m_te->BraceHighlight( bracePos1, bracePos2 );
629 m_te->SetHighlightGuide(
m_te->GetColumn( bracePos1 ) );
635 m_te->BraceHighlight( -1, -1 );
636 m_te->SetHighlightGuide( 0 );
643 wxArrayString* tokens )>& getTokensFn )
645 wxArrayString autocompleteTokens;
646 int text_pos =
m_te->GetCurrentPos();
647 int start =
m_te->WordStartPosition( text_pos,
true );
653 return pos >= 2 &&
m_te->GetCharAt( pos-2 ) ==
'$'
654 &&
m_te->GetCharAt( pos-1 ) ==
'{';
658 if( start > 1 &&
m_te->GetCharAt( start-1 ) ==
':' )
660 int refStart =
m_te->WordStartPosition( start-1,
true );
662 if( textVarRef( refStart ) )
664 partial =
m_te->GetRange( start, text_pos );
665 getTokensFn(
m_te->GetRange( refStart, start-1 ), &autocompleteTokens );
668 else if( textVarRef( start ) )
670 partial =
m_te->GetTextRange( start, text_pos );
671 getTokensFn( wxEmptyString, &autocompleteTokens );