37 std::function<
void( wxKeyEvent& )> onAcceptFn,
38 std::function<
void( wxStyledTextEvent& )> onCharAddedFn ) :
50 m_te->SetEOLMode( wxSTC_EOL_LF );
54 m_te->SetScrollWidth( 1 );
55 m_te->SetScrollWidthTracking(
true );
59 m_te->SetUseVerticalScrollBar(
false );
60 m_te->SetUseHorizontalScrollBar(
false );
66 m_te->AutoCompSetIgnoreCase(
true );
67 m_te->AutoCompSetMaxHeight( 20 );
69 if( aBraces.Length() >= 2 )
97 wxTextCtrl
dummy(
m_te->GetParent(), wxID_ANY );
100 KIGFX::COLOR4D highlight = wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHT );
101 KIGFX::COLOR4D highlightText = wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHTTEXT );
103 m_te->StyleSetForeground( wxSTC_STYLE_DEFAULT, foreground.
ToColour() );
104 m_te->StyleSetBackground( wxSTC_STYLE_DEFAULT, background.
ToColour() );
105 m_te->StyleClearAll();
109 highlight = highlight.
Mix( background, highlight.
a ).
WithAlpha( 1.0 );
110 highlightText = highlightText.
Mix( background, highlightText.
a ).
WithAlpha( 1.0 );
112 m_te->SetSelForeground(
true, highlightText.
ToColour() );
122 for(
size_t i = 0; i < wxSTC_STYLE_MAX; ++i )
123 m_te->StyleSetFont( i, fixedFont );
125 m_te->SetTabWidth( 4 );
133 m_te->StyleSetForeground( wxSTC_STYLE_BRACELIGHT, highlightText.
ToColour() );
134 m_te->StyleSetBackground( wxSTC_STYLE_BRACELIGHT, braceHighlight.
ToColour() );
135 m_te->StyleSetForeground( wxSTC_STYLE_BRACEBAD, *wxRED );
249 auto findGridTricks =
252 wxWindow* parent =
m_te->GetParent();
254 while( parent && !
dynamic_cast<WX_GRID*
>( parent ) )
255 parent = parent->GetParent();
259 wxEvtHandler* handler =
grid->GetEventHandler();
261 while( handler && !
dynamic_cast<GRID_TRICKS*
>( handler ) )
262 handler = handler->GetNextHandler();
271 wxString c = aEvent.GetUnicodeKey();
273 if(
m_te->AutoCompActive() )
275 if( aEvent.GetKeyCode() == WXK_ESCAPE )
277 m_te->AutoCompCancel();
280 else if( aEvent.GetKeyCode() == WXK_RETURN || aEvent.GetKeyCode() == WXK_NUMPAD_ENTER )
282 int start =
m_te->AutoCompPosStart();
284 m_te->AutoCompComplete();
286 int finish =
m_te->GetCurrentPos();
292 int selStart =
m_te->FindText( finish, start,
"<" );
293 int selEnd =
m_te->FindText( finish, start,
">" );
295 if( selStart > start && selEnd <= finish && selEnd > selStart )
296 m_te->SetSelection( selStart, selEnd + 1 );
308 if( aEvent.GetModifiers() == wxMOD_RAW_CONTROL && aEvent.GetKeyCode() == WXK_SPACE )
310 if( aEvent.GetModifiers() == wxMOD_CONTROL && aEvent.GetKeyCode() == WXK_SPACE )
315 wxStyledTextEvent event;
317 event.SetModifiers( wxMOD_CONTROL );
323 if( !isalpha( aEvent.GetKeyCode() ) )
326 if( ( aEvent.GetKeyCode() == WXK_RETURN || aEvent.GetKeyCode() == WXK_NUMPAD_ENTER )
335 else if( aEvent.GetKeyCode() == WXK_TAB )
337 wxWindow* ancestor =
m_te->GetParent();
339 while( ancestor && !
dynamic_cast<WX_GRID*
>( ancestor ) )
340 ancestor = ancestor->GetParent();
342 if( aEvent.ControlDown() )
346 if( !aEvent.ShiftDown() )
347 flags |= wxNavigationKeyEvent::IsForward;
350 dlg->NavigateIn( flags );
352 else if(
dynamic_cast<WX_GRID*
>( ancestor ) )
355 int row =
grid->GetGridCursorRow();
356 int col =
grid->GetGridCursorCol();
358 if( aEvent.ShiftDown() )
366 col = (int)
grid->GetNumberCols() - 1;
372 if( col < (
int)
grid->GetNumberCols() - 1 )
376 else if( row < grid->GetNumberRows() - 1 )
383 grid->SetGridCursor( row, col );
390 else if( aEvent.GetModifiers() == wxMOD_CONTROL && aEvent.GetKeyCode() ==
'Z' )
394 else if( ( aEvent.GetModifiers() == wxMOD_SHIFT+wxMOD_CONTROL && aEvent.GetKeyCode() ==
'Z' )
395 || ( aEvent.GetModifiers() == wxMOD_CONTROL && aEvent.GetKeyCode() ==
'Y' ) )
399 else if( aEvent.GetModifiers() == wxMOD_CONTROL && aEvent.GetKeyCode() ==
'A' )
403 else if( aEvent.GetModifiers() == wxMOD_CONTROL && aEvent.GetKeyCode() ==
'X' )
407 if( wxTheClipboard->Open() )
409 wxTheClipboard->Flush();
410 wxTheClipboard->Close();
413 else if( aEvent.GetModifiers() == wxMOD_CONTROL && aEvent.GetKeyCode() ==
'C' )
417 if( wxTheClipboard->Open() )
419 wxTheClipboard->Flush();
420 wxTheClipboard->Close();
423 else if( aEvent.GetModifiers() == wxMOD_CONTROL && aEvent.GetKeyCode() ==
'V' )
425 if(
m_te->GetSelectionEnd() >
m_te->GetSelectionStart() )
431 if( wxTheClipboard->Open() )
433 if( wxTheClipboard->IsSupported( wxDF_TEXT ) ||
434 wxTheClipboard->IsSupported( wxDF_UNICODETEXT ) )
436 wxTextDataObject data;
439 wxTheClipboard->GetData( data );
440 str = data.GetText();
442 if( str.Contains(
'\t' ) )
443 gridTricks = findGridTricks();
451 str.Replace( wxS(
"\n" ), wxEmptyString );
452 str.Replace( wxS(
"\r" ), wxEmptyString );
455 m_te->BeginUndoAction();
456 m_te->AddText( str );
457 m_te->EndUndoAction();
461 wxTheClipboard->Close();
467 else if( aEvent.GetKeyCode() == WXK_BACK )
469 if( aEvent.GetModifiers() == wxMOD_CONTROL )
472 else if( aEvent.GetModifiers() == wxMOD_ALT )
474 m_te->WordLeftExtend();
478 else if( aEvent.GetKeyCode() == WXK_DELETE )
480 if(
m_te->GetSelectionEnd() ==
m_te->GetSelectionStart() )
483 if( aEvent.GetModifiers() == wxMOD_CONTROL )
484 m_te->WordRightExtend();
487 m_te->CharRightExtend();
490 if(
m_te->GetSelectionEnd() >
m_te->GetSelectionStart() )
495 int startLine =
m_te->LineFromPosition(
m_te->GetSelectionStart() );
496 int endLine =
m_te->LineFromPosition(
m_te->GetSelectionEnd() );
500 m_te->BeginUndoAction();
502 for(
int ii = startLine; ii <= endLine; ++ii )
505 m_te->InsertText(
m_te->PositionFromLine( ii ), wxT(
"#" ) );
507 m_te->DeleteRange(
m_te->PositionFromLine( ii ) + whitespaceCount, 1 );
510 m_te->SetSelection(
m_te->PositionFromLine( startLine ),
511 m_te->PositionFromLine( endLine ) +
m_te->GetLineLength( endLine ) );
513 m_te->EndUndoAction();
516 else if( aEvent.GetModifiers() == wxMOD_RAW_CONTROL && aEvent.GetKeyCode() ==
'A' )
520 else if( aEvent.GetModifiers() == wxMOD_RAW_CONTROL && aEvent.GetKeyCode() ==
'E' )
524 else if( ( aEvent.GetModifiers() & wxMOD_RAW_CONTROL ) && aEvent.GetKeyCode() ==
'B' )
526 if( aEvent.GetModifiers() & wxMOD_ALT )
531 else if( ( aEvent.GetModifiers() & wxMOD_RAW_CONTROL ) && aEvent.GetKeyCode() ==
'F' )
533 if( aEvent.GetModifiers() & wxMOD_ALT )
538 else if( aEvent.GetModifiers() == wxMOD_RAW_CONTROL && aEvent.GetKeyCode() ==
'D' )
540 if(
m_te->GetSelectionEnd() ==
m_te->GetSelectionStart() )
541 m_te->CharRightExtend();
543 if(
m_te->GetSelectionEnd() >
m_te->GetSelectionStart() )
547 else if( aEvent.GetKeyCode() == WXK_SPECIAL20 )
590 [
this](
int c ) ->
bool
592 return m_braces.Find( (wxChar) c ) >= 0;
596 int caretPos =
m_te->GetCurrentPos();
597 int selStart =
m_te->GetSelectionStart();
598 int selEnd =
m_te->GetSelectionEnd();
609 if( caretPos > 0 && isBrace(
m_te->GetCharAt( caretPos-1 ) ) )
610 bracePos1 = ( caretPos - 1 );
611 else if( isBrace(
m_te->GetCharAt( caretPos ) ) )
612 bracePos1 = caretPos;
617 bracePos2 =
m_te->BraceMatch( bracePos1 );
619 if( bracePos2 == -1 )
621 m_te->BraceBadLight( bracePos1 );
622 m_te->SetHighlightGuide( 0 );
626 m_te->BraceHighlight( bracePos1, bracePos2 );
627 m_te->SetHighlightGuide(
m_te->GetColumn( bracePos1 ) );
633 m_te->BraceHighlight( -1, -1 );
634 m_te->SetHighlightGuide( 0 );
641 wxArrayString* tokens )>& getTokensFn )
643 wxArrayString autocompleteTokens;
644 int text_pos =
m_te->GetCurrentPos();
645 int start =
m_te->WordStartPosition( text_pos,
true );
651 return pos >= 2 &&
m_te->GetCharAt( pos-2 ) ==
'$'
652 &&
m_te->GetCharAt( pos-1 ) ==
'{';
656 if( start > 1 &&
m_te->GetCharAt( start-1 ) ==
':' )
658 int refStart =
m_te->WordStartPosition( start-1,
true );
660 if( textVarRef( refStart ) )
662 partial =
m_te->GetRange( start, text_pos );
663 getTokensFn(
m_te->GetRange( refStart, start-1 ), &autocompleteTokens );
666 else if( textVarRef( start ) )
668 partial =
m_te->GetTextRange( start, text_pos );
669 getTokensFn( wxEmptyString, &autocompleteTokens );