Skip to content
Permalink
Browse files

GhostTextBuffer.cpp: Fix TEST(FileCompare, LastLineEOL) failed.

(Fix broken redoing)
  • Loading branch information
sdottaka committed Jan 26, 2020
1 parent 5e13769 commit bbc4c8f6c17bc1913f23f3e9b92082dea365a5e1
Showing with 11 additions and 5 deletions.
  1. +11 −5 Src/GhostTextBuffer.cpp
@@ -795,30 +795,36 @@ OnNotifyLineHasBeenEdited(int nLine)
return;
}

static int CountEol(LPCTSTR pszText, size_t cchText)
static void CountEolAndLastLineLength(LPCTSTR pszText, size_t cchText, int &nLastLineLength, int &nEol)
{
int nEol = 0;
nLastLineLength = 0;
nEol = 0;
for (size_t nTextPos = 0; nTextPos < cchText; ++nTextPos)
{
if (LineInfo::IsEol(pszText[nTextPos]))
{
if (nTextPos + 1 < cchText && LineInfo::IsDosEol(&pszText[nTextPos]))
++nTextPos;
++nEol;
nLastLineLength = 0;
}
else
++nLastLineLength;
}
return nEol;
}


void CGhostTextBuffer:: /* virtual override */
AddUndoRecord(bool bInsert, const CPoint & ptStartPos,
const CPoint & ptEndPos, LPCTSTR pszText, size_t cchText,
int nActionType /*= CE_ACTION_UNKNOWN*/,
CDWordArray *paSavedRevisionNumbers /*= nullptr*/)
{
CPoint real_ptStartPos(ptStartPos.x, ComputeRealLine(ptStartPos.y));
CPoint real_ptEndPos(ptEndPos.x, real_ptStartPos.y + CountEol(pszText, cchText));
int nLastLineLength, nEol;
CountEolAndLastLineLength(pszText, cchText, nLastLineLength, nEol);
CPoint real_ptEndPos(ptEndPos.x, real_ptStartPos.y + nEol);
if (ptEndPos.x == 0 && cchText > 0 && !LineInfo::IsEol(pszText[cchText - 1]))
real_ptEndPos.x = nLastLineLength;
CCrystalTextBuffer::AddUndoRecord(bInsert, real_ptStartPos, real_ptEndPos, pszText,
cchText, nActionType, paSavedRevisionNumbers);
}

0 comments on commit bbc4c8f

Please sign in to comment.
You can’t perform that action at this time.