void EditTextTask::OnKeyDown(wxKeyEvent &event) { if ( m_done ) return; int code = event.GetKeyCode(); event.Skip(true); if ( code == WXK_ESCAPE ) { CloseTask(); event.Skip(false); } if ( code == WXK_DELETE || code == WXK_NUMPAD_DELETE || code == WXK_BACK ) { if ( HasSelection() ) DeleteSelection(); else if ( code == WXK_BACK ) DeleteBack(); else Delete(); event.Skip(false); } if ( code == WXK_RETURN || code == WXK_NUMPAD_ENTER ) { InsertText(_T("\n")); event.Skip(false); } if ( code == WXK_TAB ) { InsertText(_T("\t")); event.Skip(false); } }
void cbStyledTextCtrl::OnKeyDown(wxKeyEvent& event) { switch (event.GetKeyCode()) { case WXK_TAB: { if (m_tabSmartJump && !(event.ControlDown() || event.ShiftDown() || event.AltDown())) { if (!AutoCompActive() && m_bracePosition != wxSCI_INVALID_POSITION) { m_lastPosition = GetCurrentPos(); GotoPos(m_bracePosition); // Need judge if it's the final brace HighlightRightBrace(); if (!m_tabSmartJump && CallTipActive()) CallTipCancel(); return; } } } break; case WXK_BACK: { if (m_tabSmartJump) { if (!(event.ControlDown() || event.ShiftDown() || event.AltDown())) { const int pos = GetCurrentPos(); const int index = s_leftBrace.Find((wxChar)GetCharAt(pos - 1)); if (index != wxNOT_FOUND && (wxChar)GetCharAt(pos) == s_rightBrace.GetChar(index)) { CharRight(); DeleteBack(); } } else if (m_lastPosition != wxSCI_INVALID_POSITION && event.ControlDown()) { GotoPos(m_lastPosition); m_lastPosition = wxSCI_INVALID_POSITION; return; } } } break; case WXK_RETURN: case WXK_ESCAPE: { if (m_tabSmartJump) m_tabSmartJump = false; } break; } event.Skip(); }
void cbStyledTextCtrl::DoBraceCompletion(const wxChar& ch) { const int pos = GetCurrentPos(); const int style = GetStyleAt(pos); if (IsComment(style) || IsComment(GetStyleAt(pos - 2))) return; // do nothing if (ch == wxT('\'') || ch == wxT('"')) { if (GetCharAt(pos) == ch) { DeleteBack(); CharRight(); } else if (!IsString(GetStyleAt(pos - 2)) && !IsCharacter(GetStyleAt(pos - 2))) InsertText(pos, ch); return; // done } if (IsString(style) || IsCharacter(style)) return; // do nothing const wxString opBraces(wxT("([{")); const int opBraceIdx = opBraces.Find(ch); const wxString clBraces(wxT(")]}")); const int clBraceIdx = clBraces.Find(ch); if ( (opBraceIdx != wxNOT_FOUND) || (clBraceIdx != wxNOT_FOUND) ) { if ( GetCharAt(pos) == ch ) { DeleteBack(); CharRight(); } else if (opBraceIdx != wxNOT_FOUND) { int nextPos = pos; while ( wxIsspace(GetCharAt(nextPos)) && (nextPos < GetLength()) ) ++nextPos; if ( ((wxChar)GetCharAt(nextPos) != clBraces[opBraceIdx]) || (BraceMatch(nextPos) != wxNOT_FOUND) ) { InsertText(pos, clBraces[opBraceIdx]); } } } }
bool cbStyledTextCtrl::DoSelectionBraceCompletion(const wxChar& ch) { if (GetLastSelectedText().IsEmpty()) return false; // nothing changed const wxString braces(wxT("([{<'\")]}>'\"")); const int braceAIdx = braces.Find(ch, true); // from end (so caret is placed after quotes) if (braceAIdx == wxNOT_FOUND) return false; // nothing changed const int braceBIdx = (braceAIdx + (braces.Length() / 2)) % braces.Length(); BeginUndoAction(); DeleteBack(); if (braceAIdx < braceBIdx) InsertText(GetCurrentPos(), braces[braceAIdx] + GetLastSelectedText() + braces[braceBIdx]); else AddText(braces[braceBIdx] + GetLastSelectedText() + braces[braceAIdx]); EndUndoAction(); return true; // succeeded }
void cbStyledTextCtrl::OnKeyDown(wxKeyEvent& event) { m_lastSelectedText = GetSelectedText(); bool emulateDwellStart = false; switch ( event.GetKeyCode() ) { case _T('I'): { if (event.GetModifiers() == wxMOD_ALT) m_braceShortcutState = true; break; } case WXK_TAB: { if (m_tabSmartJump && event.GetModifiers() == wxMOD_NONE) { if (!AutoCompActive() && m_bracePosition != wxSCI_INVALID_POSITION) { m_lastPosition = GetCurrentPos(); GotoPos(m_bracePosition); // Need judge if it's the final brace HighlightRightBrace(); if (!m_tabSmartJump && CallTipActive()) CallTipCancel(); return; } } } break; case WXK_BACK: { if (m_tabSmartJump) { if (!(event.ControlDown() || event.ShiftDown() || event.AltDown())) { const int pos = GetCurrentPos(); const int index = s_leftBrace.Find((wxChar)GetCharAt(pos - 1)); if (index != wxNOT_FOUND && (wxChar)GetCharAt(pos) == s_rightBrace.GetChar(index)) { CharRight(); DeleteBack(); } } else if (m_lastPosition != wxSCI_INVALID_POSITION && event.ControlDown()) { GotoPos(m_lastPosition); m_lastPosition = wxSCI_INVALID_POSITION; return; } } } break; case WXK_RETURN: case WXK_NUMPAD_ENTER: case WXK_ESCAPE: { if (m_tabSmartJump) m_tabSmartJump = false; } break; case WXK_CONTROL: { EmulateDwellStart(); emulateDwellStart = true; } break; default: break; } if (event.ControlDown() && !emulateDwellStart) EmulateDwellStart(); event.Skip(); }