/* TextEditor::onKeyDown * Called when a key is pressed *******************************************************************/ void TextEditor::onKeyDown(wxKeyEvent& e) { // Check if keypress matches any keybinds wxArrayString binds = KeyBind::getBinds(KeyBind::asKeyPress(e.GetKeyCode(), e.GetModifiers())); // Go through matching binds bool handled = false; for (unsigned a = 0; a < binds.size(); a++) { string name = binds[a]; // Open/update calltip if (name == "ted_calltip") { updateCalltip(); handled = true; } // Autocomplete else if (name == "ted_autocomplete") { // Get word before cursor string word = GetTextRange(WordStartPosition(GetCurrentPos(), true), GetCurrentPos()); // If a language is loaded, bring up autocompletion list if (language) { autocomp_list = language->getAutocompletionList(word); AutoCompShow(word.size(), autocomp_list); } handled = true; } // Find/replace else if (name == "ted_findreplace") { showFindReplaceDialog(); handled = true; } // Find next else if (name == "ted_findnext") { wxCommandEvent e; onFRDBtnFindNext(e); handled = true; } // Jump to else if (name == "ted_jumpto") { openJumpToDialog(); handled = true; } } #ifdef __WXMSW__ Colourise(GetCurrentPos(), GetLineEndPosition(GetCurrentLine())); #endif #ifdef __APPLE__ if (!handled) { const int keyCode = e.GetKeyCode(); const bool shiftDown = e.ShiftDown(); if (e.ControlDown()) { if (WXK_LEFT == keyCode) { if (shiftDown) { HomeExtend(); } else { Home(); } handled = true; } else if (WXK_RIGHT == keyCode) { if (shiftDown) { LineEndExtend(); } else { LineEnd(); } handled = true; } else if (WXK_UP == keyCode) { if (shiftDown) { DocumentStartExtend(); } else { DocumentStart(); } handled = true; } else if (WXK_DOWN == keyCode) { if (shiftDown) { DocumentEndExtend(); } else { DocumentEnd(); } handled = true; } } else if (e.RawControlDown()) { if (WXK_LEFT == keyCode) { if (shiftDown) { WordLeftExtend(); } else { WordLeft(); } handled = true; } else if (WXK_RIGHT == keyCode) { if (shiftDown) { WordRightExtend(); } else { WordRight(); } handled = true; } } } #endif // __APPLE__ if (!handled) e.Skip(); }
/* TextEditor::onKeyDown * Called when a key is pressed *******************************************************************/ void TextEditor::onKeyDown(wxKeyEvent& e) { // Check if keypress matches any keybinds wxArrayString binds = KeyBind::getBinds(KeyBind::asKeyPress(e.GetKeyCode(), e.GetModifiers())); // Go through matching binds bool handled = false; for (unsigned a = 0; a < binds.size(); a++) { string name = binds[a]; // Open/update calltip if (name == "ted_calltip") { updateCalltip(); handled = true; } // Autocomplete else if (name == "ted_autocomplete") { // Get word before cursor string word = GetTextRange(WordStartPosition(GetCurrentPos(), true), GetCurrentPos()); // If a language is loaded, bring up autocompletion list if (language) { autocomp_list = language->getAutocompletionList(word); AutoCompShow(word.size(), autocomp_list); } handled = true; } // Find/replace else if (name == "ted_findreplace") { showFindReplacePanel(); handled = true; } // Find next else if (name == "ted_findnext") { if (panel_fr && panel_fr->IsShown()) findNext(panel_fr->getFindText(), panel_fr->getFindFlags()); handled = true; } // Find previous else if (name == "ted_findprev") { if (panel_fr && panel_fr->IsShown()) findPrev(panel_fr->getFindText(), panel_fr->getFindFlags()); handled = true; } // Replace next else if (name == "ted_replacenext") { if (panel_fr && panel_fr->IsShown()) replaceCurrent(panel_fr->getFindText(), panel_fr->getReplaceText(), panel_fr->getFindFlags()); handled = true; } // Replace all else if (name == "ted_replaceall") { if (panel_fr && panel_fr->IsShown()) replaceAll(panel_fr->getFindText(), panel_fr->getReplaceText(), panel_fr->getFindFlags()); handled = true; } // Fold all else if (name == "ted_fold_foldall") { foldAll(true); handled = true; } // Unfold all else if (name == "ted_fold_unfoldall") { foldAll(false); handled = true; } // Jump to line else if (name == "ted_jumptoline") { jumpToLine(); handled = true; } } // Check for esc key if (!handled && e.GetKeyCode() == WXK_ESCAPE) { // Hide call tip if showing if (call_tip->IsShown()) call_tip->Show(false); // Hide F+R panel if showing else if (panel_fr && panel_fr->IsShown()) showFindReplacePanel(false); } // Check for up/down keys while calltip with multiple arg sets is open if (call_tip->IsShown() && ct_function && ct_function->nArgSets() > 1 && !ct_dwell) { if (e.GetKeyCode() == WXK_UP) { call_tip->prevArgSet(); handled = true; } else if (e.GetKeyCode() == WXK_DOWN) { call_tip->nextArgSet(); handled = true; } } #ifdef __WXMSW__ Colourise(GetCurrentPos(), GetLineEndPosition(GetCurrentLine())); #endif #ifdef __APPLE__ if (!handled) { const int keyCode = e.GetKeyCode(); const bool shiftDown = e.ShiftDown(); if (e.ControlDown()) { if (WXK_LEFT == keyCode) { if (shiftDown) { HomeExtend(); } else { Home(); } handled = true; } else if (WXK_RIGHT == keyCode) { if (shiftDown) { LineEndExtend(); } else { LineEnd(); } handled = true; } else if (WXK_UP == keyCode) { if (shiftDown) { DocumentStartExtend(); } else { DocumentStart(); } handled = true; } else if (WXK_DOWN == keyCode) { if (shiftDown) { DocumentEndExtend(); } else { DocumentEnd(); } handled = true; } } else if (e.RawControlDown()) { if (WXK_LEFT == keyCode) { if (shiftDown) { WordLeftExtend(); } else { WordLeft(); } handled = true; } else if (WXK_RIGHT == keyCode) { if (shiftDown) { WordRightExtend(); } else { WordRight(); } handled = true; } } } #endif // __APPLE__ if (!handled) e.Skip(); }