sbuf.SetLineFlag(i, LF_WINMERGE_FLAGS, FALSE, FALSE, FALSE);
dbuf.SetLineFlag(i, LF_WINMERGE_FLAGS, FALSE, FALSE, FALSE);
// text exists on left side, so just replace
- sbuf.GetLine(i, strLine);
- dbuf.ReplaceLine(i, strLine);
+ strLine = _T("");
+ sbuf.GetFullLine(i, strLine);
+ dbuf.ReplaceFullLine(i, strLine);
dbuf.FlushUndoGroup(curView);
dbuf.BeginUndoGroup(TRUE);
}
return bSuccess;
}
+// Replace text of line (no change to eol)
void CMergeDoc::CDiffTextBuffer::ReplaceLine(int nLine, const CString &strText)
{
if (GetLineLength(nLine)>0)
int endl,endc;
InsertText(NULL, nLine, 0, strText, endl,endc);
}
+// return pointer to the eol chars of this string, or pointer to empty string if none
+LPCTSTR getEol(const CString &str)
+{
+ if (str.GetLength()>1 && str[str.GetLength()-2]=='\r' && str[str.GetLength()-1]=='\n')
+ return (LPCTSTR)str + str.GetLength()-2;
+ if (str.GetLength()>0 && (str[str.GetLength()-1]=='\r' || str[str.GetLength()-1]=='\n'))
+ return (LPCTSTR)str + str.GetLength()-1;
+ return _T("");
+}
+
+// Replace line (removing any eol, and only including one if in strText)
+void CMergeDoc::CDiffTextBuffer::ReplaceFullLine(int nLine, const CString &strText)
+{
+ if (GetLineEol(nLine) == getEol(strText))
+ {
+ // (optimization) eols are the same, so just replace text inside line
+ ReplaceLine(nLine, strText);
+ return;
+ }
+ if (GetFullLineLength(nLine))
+ DeleteText(NULL, nLine, 0, nLine+1, 0);
+ int endl,endc;
+ InsertText(NULL, nLine, 0, strText, endl,endc);
+}
BOOL CMergeDoc::InitTempFiles(const CString& srcPathL, const CString& strPathR)
{
int DetermineCRLFStyle(LPVOID lpBuf, DWORD dwLength);
void ReadLineFromBuffer(TCHAR *lpLineBegin, DWORD dwLineLen = 0);
public :
- bool curUndoGroup();
- void ReplaceLine(int nLine, const CString& strText);
+ bool curUndoGroup();
+ void ReplaceLine(int nLine, const CString& strText);
+ void ReplaceFullLine(int nLine, const CString& strText);
+
UINT GetTextWithoutEmptys(int nStartLine, int nStartChar, int nEndLine, int nEndChar,
CString &text, BOOL bLeft, int nCrlfStyle = CRLF_STYLE_AUTOMATIC);
BOOL LoadFromFile(LPCTSTR pszFileName, int nCrlfStyle = CRLF_STYLE_AUTOMATIC);
int nCrlfStyle = CRLF_STYLE_AUTOMATIC,
BOOL bClearModifiedFlag = TRUE );
- CDiffTextBuffer (CMergeDoc * pDoc, BOOL bLeft)
- {
- m_pOwnerDoc = pDoc;
- m_bIsLeft=bLeft;
- }
+ CDiffTextBuffer (CMergeDoc * pDoc, BOOL bLeft)
+ {
+ m_pOwnerDoc = pDoc;
+ m_bIsLeft=bLeft;
+ }
+ // If line has text (excluding eol), set strLine to text (excluding eol)
BOOL GetLine( int nLineIndex, CString &strLine )
{
int nLineLength = CCrystalTextBuffer::GetLineLength
}
return TRUE;
}
+ // if line has any text (including eol), set strLine to text (including eol)
+ BOOL GetFullLine(int nLineIndex, CString &strLine)
+ {
+ if (!GetFullLineLength(nLineIndex))
+ return FALSE;
+ strLine = GetLineChars(nLineIndex);
+ return TRUE;
+ }
- virtual void SetModified (BOOL bModified = TRUE)
- {
- CCrystalTextBuffer::SetModified (bModified);
- m_pOwnerDoc->SetModifiedFlag (bModified);
- }
+ virtual void SetModified (BOOL bModified = TRUE)
+ {
+ CCrystalTextBuffer::SetModified (bModified);
+ m_pOwnerDoc->SetModifiedFlag (bModified);
+ }
void InsertLine (LPCTSTR pszLine, int nLength = -1, int nPosition = -1)
{
CCrystalTextBuffer::InsertLine(pszLine, nLength, nPosition);
return m_aLines.GetSize ();
}
+// number of characters in line (excluding any trailing eol characters)
int CCrystalTextBuffer::
GetLineLength (int nLine)
{
return m_aLines[nLine].m_nLength;
}
+// number of characters in line (including any trailing eol characters)
int CCrystalTextBuffer::
GetFullLineLength (int nLine)
{
return m_aLines[nLine].m_nLength + m_aLines[nLine].m_nEolChars;
}
+// get pointer to any trailing eol characters (pointer to empty string if none)
+LPCTSTR CCrystalTextBuffer::
+GetLineEol (int nLine)
+{
+ ASSERT (m_bInit); // Text buffer not yet initialized.
+ if (m_aLines[nLine].m_nEolChars)
+ return &m_aLines[nLine].m_pcLine[m_aLines[nLine].Length()];
+ else
+ return _T("");
+}
+
LPTSTR CCrystalTextBuffer::
GetLineChars (int nLine)
{
InsertText (CCrystalTextView * pSource, int nLine, int nPos, LPCTSTR pszText,
int &nEndLine, int &nEndChar, int nAction, BOOL bUpdate /*=TRUE*/)
{
- // Are we inserting into a ghost line not at the end of the file, without EOL ?
- if (nLine < GetLineCount() && !GetFullLineLength(nLine) && !HasEol(pszText))
+ // Are we inserting into a ghost line without EOL ?
+ if (!GetFullLineLength(nLine) && !HasEol(pszText))
{
- // terminate line with default EOL
- CString str = pszText;
- str += GetDefaultEol();
- return InsertText(pSource, nLine, nPos, str, nEndLine, nEndChar, nAction, bUpdate);
+ // Is there any text after this line ?
+ if (m_RealityBlocks.GetSize() && m_RealityBlocks[m_RealityBlocks.GetUpperBound()].nStartApparent > nLine)
+ {
+ // terminate line with default EOL
+ CString str = pszText;
+ str += GetDefaultEol();
+ return InsertText(pSource, nLine, nPos, str, nEndLine, nEndChar, nAction, bUpdate);
+ }
}
int nRealStart = ComputeRealLine(nLine);
int GetLineCount ();
int GetLineLength (int nLine);
int GetFullLineLength (int nLine); // including EOLs
+ LPCTSTR GetLineEol (int nLine);
LPTSTR GetLineChars (int nLine);
DWORD GetLineFlags (int nLine);
int GetLineWithFlag (DWORD dwFlag);
WinMerge: MergeEditView.cpp
PATCH: [ 762533 ] Stdafx.h has dublicated and unneeded includes
WinMerge: StdAfx.h
+ PATCH: [ 762271 ] Alter ListCopy to copy eol chars
+ WinMerge: MergeDoc.cpp MergeDoc.h
+ editlib: ccrystaltextbuffer.h ccrystaltextbuffer.cpp
2003-06-29 Kimmo
PATCH: [ 762749 ] Forced rescan after options changed