OSDN Git Service

PATCH: [ 762271 ] Alter ListCopy to copy eol chars
authorPerry Rapp <elsapo@users.sourceforge.net>
Sun, 29 Jun 2003 17:41:03 +0000 (17:41 +0000)
committerPerry Rapp <elsapo@users.sourceforge.net>
Sun, 29 Jun 2003 17:41:03 +0000 (17:41 +0000)
Src/MergeDoc.cpp
Src/MergeDoc.h
Src/editlib/ccrystaltextbuffer.cpp
Src/editlib/ccrystaltextbuffer.h
Src/readme.txt

index 34fec16..3e09a38 100644 (file)
@@ -710,8 +710,9 @@ void CMergeDoc::ListCopy(bool bSrcLeft)
                        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);
                }
@@ -1284,6 +1285,7 @@ BOOL CMergeDoc::CDiffTextBuffer::SaveToFile (LPCTSTR pszFileName,
        return bSuccess;
 }
 
+// Replace text of line (no change to eol)
 void CMergeDoc::CDiffTextBuffer::ReplaceLine(int nLine, const CString &strText)
 {
        if (GetLineLength(nLine)>0)
@@ -1291,6 +1293,30 @@ void CMergeDoc::CDiffTextBuffer::ReplaceLine(int nLine, const CString &strText)
        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)
 {
index 5b820a5..b7d6d73 100644 (file)
@@ -84,8 +84,10 @@ private :
                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);
@@ -93,11 +95,12 @@ public :
                                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 
@@ -116,12 +119,20 @@ public :
                        } 
                        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);
index 6eaee2a..c9dc91e 100644 (file)
@@ -674,6 +674,7 @@ GetLineCount ()
   return m_aLines.GetSize ();
 }
 
+// number of characters in line (excluding any trailing eol characters)
 int CCrystalTextBuffer::
 GetLineLength (int nLine)
 {
@@ -683,6 +684,7 @@ GetLineLength (int nLine)
   return m_aLines[nLine].m_nLength;
 }
 
+// number of characters in line (including any trailing eol characters)
 int CCrystalTextBuffer::
 GetFullLineLength (int nLine)
 {
@@ -692,6 +694,17 @@ 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)
 {
@@ -1433,13 +1446,17 @@ BOOL CCrystalTextBuffer::
 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);
index d0bf5f8..1fed6cc 100644 (file)
@@ -300,6 +300,7 @@ public :
     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);
index 98ff278..13afdcc 100644 (file)
@@ -3,6 +3,9 @@
   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