BOOL TextView::BackDelete() { ULONG selstart = min(m_nSelectionStart, m_nSelectionEnd); ULONG selend = max(m_nSelectionStart, m_nSelectionEnd); // if there's a selection then delete it if(selstart != selend) { m_pTextDoc->erase_text(selstart, selend-selstart); m_nCursorOffset = selstart; m_pTextDoc->m_seq.breakopt(); } // otherwise do a back-delete else if(m_nCursorOffset > 0) { //m_nCursorOffset--; ULONG oldpos = m_nCursorOffset; MoveCharPrev(); //m_pTextDoc->erase_text(m_nCursorOffset, 1); m_pTextDoc->erase_text(m_nCursorOffset, oldpos - m_nCursorOffset); } m_nSelectionStart = m_nCursorOffset; m_nSelectionEnd = m_nCursorOffset; ResetLineCache(); RefreshWindow(); Smeg(FALSE); return TRUE; }
// // Process keyboard-navigation keys // LONG TextViewBase::OnKeyDown(UINT nKeyCode, UINT nFlags) { bool fCtrlDown = IsKeyPressed(VK_CONTROL); bool fShiftDown = IsKeyPressed(VK_SHIFT); BOOL fAdvancing = FALSE; long oldCursorOffset = m_nSelectionEnd; // // Process the key-press. Cursor movement is different depending // on if <ctrl> is held down or not, so act accordingly // switch(nKeyCode) { case VK_SHIFT: case VK_CONTROL: return 0; case 'a': case 'A': { if(fCtrlDown) SelectAll(); } return 0; // CTRL+Z undo case 'z': case 'Z': if(fCtrlDown && Undo()) /*NotifyParent(TVN_CHANGED);*/ return 0; // CTRL+Y redo case 'y': case 'Y': if(fCtrlDown && Redo()) //NotifyParent(TVN_CHANGED); return 0; // CTRL+C copy case 'c': case 'C': { //if(fCtrlDown && Redo()) // NotifyParent(TVN_CHANGED); if(fCtrlDown) return OnCopy(); else break; } case 'x': case 'X': { if(fCtrlDown) return OnCut(); else break; } case 'v': case 'V': { if(fCtrlDown) return OnPaste(); else break; } // Change insert mode / clipboard copy&paste case VK_INSERT: if(fCtrlDown) { OnCopy(); NotifyParent(TVN_CHANGED); } else if(fShiftDown) { OnPaste(); NotifyParent(TVN_CHANGED); } else { if(m_nEditMode == MODE_INSERT) m_nEditMode = MODE_OVERWRITE; else if(m_nEditMode == MODE_OVERWRITE) m_nEditMode = MODE_INSERT; NotifyParent(TVN_EDITMODE_CHANGE); } return 0; case VK_DELETE: if(m_nEditMode != MODE_READONLY) { if(fShiftDown) OnCut(); else ForwardDelete(); NotifyParent(TVN_CHANGED); } return 0; case VK_BACK: if(m_nEditMode != MODE_READONLY) { BackDelete(); fAdvancing = FALSE; NotifyParent(TVN_CHANGED); } return 0; case VK_LEFT: if(fCtrlDown) MoveWordPrev(); else MoveCharPrev(); fAdvancing = FALSE; break; case VK_RIGHT: if(fCtrlDown) MoveWordNext(); else MoveCharNext(); fAdvancing = TRUE; break; case VK_UP: if(fCtrlDown) Scroll(0, -1); else MoveLineUp(1); break; case VK_DOWN: if(fCtrlDown) Scroll(0, 1); else MoveLineDown(1); break; case VK_PRIOR: if(!fCtrlDown) MovePageUp(); break; case VK_NEXT: if(!fCtrlDown) MovePageDown(); break; case VK_HOME: if(fCtrlDown) MoveFileStart(); else MoveLineStart(m_nCurrentLine); break; case VK_END: if(fCtrlDown) MoveFileEnd(); else MoveLineEnd(m_nCurrentLine); break; default: return 0; } // Extend selection if <shift> is down if(fShiftDown) { InvalidateRange(m_nSelectionEnd, oldCursorOffset); //m_nSelectionEnd = m_nCursorOffset; } // Otherwise clear the selection else { if(m_nSelectionStart != m_nSelectionEnd) InvalidateRange(m_nSelectionStart, m_nSelectionEnd); //m_nSelectionEnd = m_nCursorOffset; m_nSelectionStart = m_nSelectionEnd; } // update caret-location (xpos, line#) from the offset //UpdateCaretOffset(m_nCursorOffset, fAdvancing, &m_nCaretPosX, &m_nCurrentLine); CHAR_POS cp; FilePosToCharPos(m_nSelectionEnd, &cp); m_nCurrentLine_D = cp.logLine; // maintain the caret 'anchor' position *except* for up/down actions if(nKeyCode != VK_UP && nKeyCode != VK_DOWN) { //m_nAnchorPosX = m_nCaretPosX; // scroll as necessary to keep caret within viewport //ScrollToPosition(m_nCaretPosX, m_nCurrentLine); } else { // scroll as necessary to keep caret within viewport if(!fCtrlDown); //ScrollToPosition(m_nCaretPosX, m_nCurrentLine); } NotifyParent(TVN_CURSOR_CHANGE); return 0; }
BOOL TextViewBase::BackDelete() { ULONG selstart = min(m_nSelectionStart, m_nSelectionEnd); ULONG selend = max(m_nSelectionStart, m_nSelectionEnd); ULONG length = selend - selstart; bool nead_Smeg = false; ULONG line_offset, line_length, line_no; m_pTextDoc->lineinfo_from_offset(selstart, &line_no, &line_offset, &line_length, NULL, NULL); //m_pTextDoc->lineinfo_from_lineno(m_nCurrentLine_D, &line_offset, &line_length, NULL, NULL); // if there's a selection then delete it if(selstart != selend) { if(selstart + length >= line_length + line_offset) { nead_Smeg = true; } m_pTextDoc->erase_text(selstart, selend-selstart); m_nSelectionEnd = selstart; m_pTextDoc->m_seq.breakopt(); } // otherwise do a back-delete else if (m_nSelectionEnd > 0) { //m_nCursorOffset--; ULONG oldpos = m_nSelectionEnd; MoveCharPrev(); length = oldpos - m_nSelectionEnd; if (m_nSelectionEnd < line_offset) { nead_Smeg = true; } m_pTextDoc->erase_text(m_nSelectionEnd, length); } m_nSelectionStart = m_nSelectionEnd; //m_nSelectionEnd = m_nCursorOffset; //FilePosToCharPos(m_nCursorOffset, &m_CurrentCharPos); if(nead_Smeg) { Smeg(FALSE); }else { int old_offset = m_nSelectionEnd; m_pTextDoc->init_linebuffer(); ResetLineCache( m_nCurrentLine_D); //FilePosToCharPos(m_nCursorOffset, &m_CurrentCharPos); MoveLineStart(0, false); InvalidateRange((m_nSelectionEnd ? m_nSelectionEnd - 1 : 0), line_offset + line_length); m_nSelectionEnd = old_offset; RepositionCaret(); } #ifdef _DEBUG wchar_t db_string[200]; wsprintf(db_string, L"m_nSelectionEnd=%d\n", m_nSelectionEnd); OutputDebugString(db_string); #endif return TRUE; }