📄 ccrystaleditview.cpp
字号:
else if (nAction == CE_ACTION_TYPING && (GetFlags () & (SRCOPT_BRACEGNU|SRCOPT_BRACEANSI)) && isclosebrace (pszText))
{
// Enter stroke!
CPoint ptCursorPos = GetCursorPos ();
// Take indentation from the previos line
int nLength = m_pTextBuffer->GetLineLength (ptCursorPos.y);
LPCTSTR pszLineChars = m_pTextBuffer->GetLineChars (ptCursorPos.y );
int nPos = 0;
while (nPos < nLength && isspace (pszLineChars[nPos]))
nPos++;
if (ptCursorPos.y > 0 && nPos && nPos == nLength - 1)
{
if (pszLineChars[nPos - 1] == _T ('\t'))
{
nPos = 1;
}
else
{
int nTabSize = GetTabSize ();
nPos = nTabSize - (ptCursorPos.x - 1) % nTabSize;
if (!nPos)
{
nPos = nTabSize;
}
if (nPos > nLength - 1)
{
nPos = nLength - 1;
}
}
// m_pTextBuffer->BeginUndoGroup ();
m_pTextBuffer->DeleteText (NULL, ptCursorPos.y, ptCursorPos.x - nPos - 1,
ptCursorPos.y, ptCursorPos.x - 1, CE_ACTION_AUTOINDENT);
ptCursorPos.x -= nPos;
SetCursorPos (ptCursorPos);
SetSelection (ptCursorPos, ptCursorPos);
SetAnchor (ptCursorPos);
EnsureVisible (ptCursorPos);
// m_pTextBuffer->FlushUndoGroup (this);
}
}
}
}
void CCrystalEditView::
OnEditAutoComplete ()
{
CPoint ptCursorPos = GetCursorPos ();
int nLength = m_pTextBuffer->GetLineLength (ptCursorPos.y);
LPCTSTR pszText = m_pTextBuffer->GetLineChars (ptCursorPos.y), pszEnd = pszText + ptCursorPos.x;
if (ptCursorPos.x > 0 && ptCursorPos.y > 0 && (nLength == ptCursorPos.x || !xisalnum (*pszEnd)) && xisalnum (pszEnd[-1]))
{
LPCTSTR pszBegin = pszEnd - 1;
while (pszBegin > pszText && xisalnum (*pszBegin))
pszBegin--;
if (!xisalnum (*pszBegin))
pszBegin++;
nLength = pszEnd - pszBegin;
CString sText;
LPTSTR pszBuffer = sText.GetBuffer (nLength + 2);
*pszBuffer = _T('<');
_tcsncpy (pszBuffer + 1, pszBegin, nLength);
pszBuffer[nLength + 1] = _T('\0');
sText.ReleaseBuffer ();
CPoint ptTextPos;
ptCursorPos.x -= nLength;
BOOL bFound = FindText (sText, ptCursorPos, FIND_MATCH_CASE|FIND_REGEXP|FIND_DIRECTION_UP, TRUE, &ptTextPos);
if (!bFound)
{
ptCursorPos.x += nLength;
bFound = FindText (sText, ptCursorPos, FIND_MATCH_CASE|FIND_REGEXP, TRUE, &ptTextPos);
ptCursorPos.x -= nLength;
}
if (bFound)
{
int nFound = m_pTextBuffer->GetLineLength (ptTextPos.y);
pszText = m_pTextBuffer->GetLineChars (ptTextPos.y) + ptTextPos.x + m_nLastFindWhatLen;
nFound -= ptTextPos.x + m_nLastFindWhatLen;
pszBuffer = sText.GetBuffer (nFound + 1);
while (nFound-- && xisalnum (*pszText))
*pszBuffer++ = *pszText++;
*pszBuffer = _T('\0');
sText.ReleaseBuffer ();
if (!sText.IsEmpty ())
{
m_pTextBuffer->BeginUndoGroup ();
int x, y;
m_pTextBuffer->InsertText (this, ptCursorPos.y, ptCursorPos.x + nLength, sText, y, x, CE_ACTION_AUTOCOMPLETE);
ptCursorPos.x = x;
ptCursorPos.y = y;
SetCursorPos (ptCursorPos);
SetSelection (ptCursorPos, ptCursorPos);
SetAnchor (ptCursorPos);
EnsureVisible (ptCursorPos);
m_pTextBuffer->FlushUndoGroup (this);
}
}
}
}
void CCrystalEditView::
OnUpdateEditAutoComplete (CCmdUI * pCmdUI)
{
CPoint ptCursorPos = GetCursorPos ();
int nLength = m_pTextBuffer->GetLineLength (ptCursorPos.y);
LPCTSTR pszText = m_pTextBuffer->GetLineChars (ptCursorPos.y) + ptCursorPos.x;
pCmdUI->Enable (ptCursorPos.x > 0 && ptCursorPos.y > 0 && (nLength == ptCursorPos.x || !xisalnum (*pszText)) && xisalnum (pszText[-1]));
}
void CCrystalEditView::
OnEditAutoExpand ()
{
CPoint ptCursorPos = GetCursorPos ();
int nLength = m_pTextBuffer->GetLineLength (ptCursorPos.y);
LPCTSTR pszText = m_pTextBuffer->GetLineChars (ptCursorPos.y), pszEnd = pszText + ptCursorPos.x;
if (ptCursorPos.x > 0 && ptCursorPos.y > 0 && (nLength == ptCursorPos.x || !xisalnum (*pszEnd)) && xisalnum (pszEnd[-1]))
{
LPCTSTR pszBegin = pszEnd - 1;
while (pszBegin > pszText && xisalnum (*pszBegin))
pszBegin--;
if (!xisalnum (*pszBegin))
pszBegin++;
nLength = pszEnd - pszBegin;
CString sText, sExpand;
LPTSTR pszBuffer = sText.GetBuffer (nLength + 1);
_tcsncpy (pszBuffer, pszBegin, nLength);
pszBuffer[nLength] = _T('\0');
sText.ReleaseBuffer ();
CPoint ptTextPos;
ptCursorPos.x -= nLength;
BOOL bFound = m_mapExpand->Lookup (sText, sExpand);
if (bFound && !sExpand.IsEmpty ())
{
m_pTextBuffer->BeginUndoGroup ();
int x, y;
m_pTextBuffer->DeleteText (this, ptCursorPos.y, ptCursorPos.x, ptCursorPos.y, ptCursorPos.x + nLength, CE_ACTION_AUTOEXPAND);
LPTSTR pszExpand = sExpand.GetBuffer (sExpand.GetLength () + 1);
LPTSTR pszSlash = _tcschr (pszExpand, _T ('\\'));
if (!pszSlash)
{
m_pTextBuffer->InsertText (this, ptCursorPos.y, ptCursorPos.x, pszExpand, y, x, CE_ACTION_AUTOEXPAND);
ptCursorPos.x = x;
ptCursorPos.y = y;
ASSERT_VALIDTEXTPOS (ptCursorPos);
SetCursorPos (ptCursorPos);
SetSelection (ptCursorPos, ptCursorPos);
SetAnchor (ptCursorPos);
}
else
{
*pszSlash++ = _T ('\0');
for(;;)
{
m_pTextBuffer->InsertText (this, ptCursorPos.y, ptCursorPos.x, pszExpand, y, x, CE_ACTION_AUTOEXPAND);
ptCursorPos.x = x;
ptCursorPos.y = y;
ASSERT_VALIDTEXTPOS (ptCursorPos);
SetCursorPos (ptCursorPos);
SetSelection (ptCursorPos, ptCursorPos);
SetAnchor (ptCursorPos);
OnEditOperation (CE_ACTION_TYPING, pszExpand);
ptCursorPos = GetCursorPos ();
if (!pszSlash)
break;
switch (*pszSlash)
{
case _T ('n'):
{
const static TCHAR szText[3] = _T ("\r\n");
m_pTextBuffer->InsertText (this, ptCursorPos.y, ptCursorPos.x, szText, y, x, CE_ACTION_AUTOEXPAND); // [JRT]
ptCursorPos.x = x;
ptCursorPos.y = y;
ASSERT_VALIDTEXTPOS (ptCursorPos);
SetSelection (ptCursorPos, ptCursorPos);
SetAnchor (ptCursorPos);
SetCursorPos (ptCursorPos);
OnEditOperation (CE_ACTION_TYPING, szText);
}
break;
case _T ('u'):
MoveUp (FALSE);
break;
case _T ('d'):
MoveDown (FALSE);
break;
case _T ('l'):
MoveLeft (FALSE);
break;
case _T ('r'):
MoveRight (FALSE);
break;
case _T ('h'):
MoveHome (FALSE);
break;
case _T ('f'):
MoveEnd (FALSE);
break;
case _T ('b'):
{
CPoint ptSelStart = ptCursorPos;
bool bDeleted = false;
if (!(ptCursorPos.x)) // If At Start Of Line
{
if (!m_bDisableBSAtSOL) // If DBSASOL Is Disabled
{
if (ptCursorPos.y > 0) // If Previous Lines Available
{
ptCursorPos.y--; // Decrement To Previous Line
ptCursorPos.x = GetLineLength (
ptCursorPos.y); // Set Cursor To End Of Previous Line
bDeleted = true; // Set Deleted Flag
}
}
}
else // If Caret Not At SOL
{
ptCursorPos.x--; // Decrement Position
bDeleted = true; // Set Deleted Flag
}
ASSERT_VALIDTEXTPOS (ptCursorPos);
SetAnchor (ptCursorPos);
SetSelection (ptCursorPos, ptCursorPos);
SetCursorPos (ptCursorPos);
if (bDeleted)
m_pTextBuffer->DeleteText (this, ptCursorPos.y, ptCursorPos.x, ptSelStart.y, ptSelStart.x, CE_ACTION_AUTOEXPAND); // [JRT]
}
break;
case _T ('e'):
{
CPoint ptSelEnd = ptCursorPos;
if (ptSelEnd.x == GetLineLength (ptSelEnd.y))
{
if (ptSelEnd.y == GetLineCount () - 1)
break;
ptSelEnd.y++;
ptSelEnd.x = 0;
}
else
ptSelEnd.x++;
m_pTextBuffer->DeleteText (this, ptCursorPos.y, ptCursorPos.x, ptSelEnd.y, ptSelEnd.x, CE_ACTION_AUTOEXPAND); // [JRT]
}
break;
case _T ('t'):
{
static TCHAR szText[32];
if (m_bInsertTabs)
{
*szText = _T ('\t');
szText[1] = _T ('\0');
}
else
{
int nTabSize = GetTabSize ();
int nChars = nTabSize - ptCursorPos.x % nTabSize;
memset(szText, _T(' '), nChars);
szText[nChars] = _T ('\0');
}
m_pTextBuffer->InsertText (this, ptCursorPos.y, ptCursorPos.x, szText, y, x, CE_ACTION_AUTOEXPAND); // [JRT]
ptCursorPos.x = x;
ptCursorPos.y = y;
ASSERT_VALIDTEXTPOS (ptCursorPos);
SetSelection (ptCursorPos, ptCursorPos);
SetAnchor (ptCursorPos);
SetCursorPos (ptCursorPos);
}
}
ptCursorPos = GetCursorPos ();
pszExpand = pszSlash + 1;
pszSlash = _tcschr (pszExpand, _T ('\\'));
if (pszSlash)
*pszSlash++ = _T ('\0');
}
}
sExpand.ReleaseBuffer ();
EnsureVisible (ptCursorPos);
m_pTextBuffer->FlushUndoGroup (this);
}
}
}
void CCrystalEditView::
OnUpdateEditAutoExpand (CCmdUI * pCmdUI)
{
if (m_mapExpand->IsEmpty ())
pCmdUI->Enable (FALSE);
else
OnUpdateEditAutoComplete (pCmdUI);
}
void CCrystalEditView::
OnUpdateEditLowerCase (CCmdUI * pCmdUI)
{
pCmdUI->Enable (IsSelection ());
}
void CCrystalEditView::
OnEditLowerCase ()
{
if (IsSelection ())
{
CPoint ptCursorPos = GetCursorPos ();
CPoint ptSelStart, ptSelEnd;
GetSelection (ptSelStart, ptSelEnd);
CString text;
GetText (ptSelStart, ptSelEnd, text);
text.MakeLower ();
m_pTextBuffer->BeginUndoGroup ();
if (IsSelection ())
{
CPoint ptSelStart, ptSelEnd;
GetSelection (ptSelStart, ptSelEnd);
ptCursorPos = ptSelStart;
/*SetAnchor (ptCursorPos);
SetSelection (ptCursorPos, ptCursorPos);
SetCursorPos (ptCursorPos);
EnsureVisible (ptCursorPos);*/
// [JRT]:
m_pTextBuffer->DeleteText (this, ptSelStart.y, ptSelStart.x, ptSelEnd.y, ptSelEnd.x, CE_ACTION_LOWERCASE);
}
int x, y;
m_pTextBuffer->InsertText (this, ptSelStart.y, ptSelStart.x, text, y, x, CE_ACTION_LOWERCASE);
ASSERT_VALIDTEXTPOS (ptCursorPos);
SetAnchor (ptCursorPos);
SetSelection (ptSelStart, ptSelEnd);
SetCursorPos (ptCursorPos);
EnsureVisible (ptCursorPos);
m_pTextBuffer->FlushUndoGroup (this);
}
}
void CCrystalEditView::
OnUpdateEditUpperCase (CCmdUI * pCmdUI)
{
pCmdUI->Enable (IsSelection ());
}
void CCrystalEditView::
OnEditUpperCase ()
{
if (IsSelection ())
{
CPoint ptCursorPos = GetCursorPos ();
CPoint ptSelStart, ptSelEnd;
GetSelection (ptSelStart, ptSelEnd);
CString text;
GetText (ptSelStart, ptSelEnd, text);
text.MakeUpper ();
m_pTextBuffer->BeginUndoGroup ();
if (IsSelection ())
{
CPoint ptSelStart, ptSelEnd;
GetSelection (ptSelStart, ptSelEnd);
ptCursorPos = ptSelStart;
/*SetAnchor (ptCursorPos);
SetSelection (ptCursorPos, ptCursorPos);
SetCursorPos (ptCursorPos);
EnsureVisible (ptCursorPos);*/
// [JRT]:
m_pTextBuffer->DeleteText (this, ptSelStart.y, ptSelStart.x, ptSelEnd.y, ptSelEnd.x, CE_ACTION_UPPERCASE);
}
int x, y;
m_pTextBuffer->InsertText (this, ptSelStart.y, ptSelStart.x, text, y, x, CE_ACTION_UPPERCASE);
ASSERT_VALIDTEXTPOS (ptCursorPos);
SetAnchor (ptCursorPos);
SetSelection (ptSelStart, ptSelEnd);
SetCursorPos (ptCursorPos);
EnsureVisible (ptCursorPos);
m_pTextBuffer->FlushUndoGroup (this);
}
}
void CCrystalEditView::
OnUpdateEditSwapCase (CCmdUI * pCmdUI)
{
pCmdUI->Enable (IsSelection ());
}
void CCrystalEditView::
OnEditSwapCase ()
{
if (IsSelection ())
{
CPoint ptCursorPos = GetCursorPos ();
CPoint ptSelStart, ptSelEnd;
GetSelection (ptSelStart, ptSelEnd);
CString text;
GetText (ptSelStart, ptSelEnd, text);
int nLen = text.GetLength ();
LPTSTR pszText
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -