OSDN Git Service

PATCH: [ 711437 ] Don't copy/cut removed lines
authorKimmo Varis <kimmov@gmail.com>
Mon, 31 Mar 2003 19:25:53 +0000 (19:25 +0000)
committerKimmo Varis <kimmov@gmail.com>
Mon, 31 Mar 2003 19:25:53 +0000 (19:25 +0000)
Src/MergeDoc.cpp
Src/MergeDoc.h
Src/MergeEditView.cpp
Src/readme.txt

index bdca484..0a9a853 100644 (file)
@@ -970,6 +970,119 @@ void CMergeDoc::SetCurrentDiff(int nDiff)
                m_nCurDiff = -1;
 }
 
+BOOL CMergeDoc::CDiffTextBuffer::FlagIsSet(UINT line, DWORD flag)
+{
+       return ((m_aLines[line].m_dwFlags & flag) == flag);
+}
+
+// Get text ignoring removed lines
+// CrystalTextBuffer::GetText() returns text including removed lines
+UINT CMergeDoc::CDiffTextBuffer::GetTextWithoutEmptys(int nStartLine, int nStartChar, 
+                                                                int nEndLine, int nEndChar, 
+                                                                CString &text, BOOL bLeft, int nCrlfStyle /* CRLF_STYLE_AUTOMATIC */)
+{
+       int lines = m_aLines.GetSize();
+       ASSERT(nStartLine >= 0 && nStartLine < lines);
+       ASSERT(nStartChar >= 0 && nStartChar <= m_aLines[nStartLine].m_nLength);
+       ASSERT(nEndLine >= 0 && nEndLine < lines);
+       ASSERT(nEndChar >= 0 && nEndChar <= m_aLines[nEndLine].m_nLength);
+       ASSERT(nStartLine < nEndLine || nStartLine == nEndLine && 
+               nStartChar < nEndChar);
+       
+       if (nCrlfStyle == CRLF_STYLE_AUTOMATIC)
+               nCrlfStyle = GetCRLFMode();
+               
+       ASSERT(nCrlfStyle >= 0 && nCrlfStyle <= 2);
+       LPCTSTR pszCRLF = crlfs[nCrlfStyle];
+       
+       int nCRLFLength = _tcslen(pszCRLF);
+       ASSERT(nCRLFLength > 0);
+       
+       int nBufSize = 0;
+       
+       // Count text length (incl. linefeeds)
+       for (int i = nStartLine; i <= nEndLine; i++)
+       {
+               // Skip blank diff lines
+               if ((!m_bIsLeft && !FlagIsSet(i, LF_LEFT_ONLY)) ||
+                                       ( m_bIsLeft && !FlagIsSet(i, LF_RIGHT_ONLY)))
+               {
+                       nBufSize += m_aLines[i].m_nLength;
+                       nBufSize += nCRLFLength;
+               }
+       }
+       
+       LPTSTR pszBuf = text.GetBuffer(nBufSize);
+       
+       // Multiple lines
+       if (nStartLine < nEndLine)
+       {
+               // Skip blank diff lines
+               if ((!m_bIsLeft && !FlagIsSet(nStartLine, LF_LEFT_ONLY)) ||
+                               (m_bIsLeft && !FlagIsSet(nStartLine, LF_RIGHT_ONLY)))
+               {
+                       // Copy (part of) first line
+                       int nCount = m_aLines[nStartLine].m_nLength - nStartChar;
+                       if (nCount > 0)
+                       {
+                               CopyMemory(pszBuf, m_aLines[nStartLine].m_pcLine + nStartChar,
+                                       nCount * sizeof(TCHAR));
+                               pszBuf += nCount;
+                       }
+                       CopyMemory(pszBuf, pszCRLF, nCRLFLength * sizeof(TCHAR));
+                       pszBuf += nCRLFLength;
+               }
+               
+               // Other lines
+               for (i = nStartLine + 1; i < nEndLine; i++)
+               {
+                       // Skip blank diff lines
+                       if ((!m_bIsLeft && !FlagIsSet(i, LF_LEFT_ONLY)) ||
+                                       (m_bIsLeft && !FlagIsSet(i, LF_RIGHT_ONLY)))
+                       {
+                               int nCount = m_aLines[i].m_nLength;
+                               if (nCount > 0)
+                               {
+                                       CopyMemory(pszBuf, m_aLines[i].m_pcLine,
+                                               nCount * sizeof(TCHAR));
+                                       pszBuf += nCount;
+                               }
+                               CopyMemory(pszBuf, pszCRLF, nCRLFLength * sizeof(TCHAR));
+                               pszBuf += nCRLFLength;
+                       }
+               }
+               
+               // Last line
+               if (nEndChar > 0)
+               {
+                       // Skip blank diff lines
+                       if ((!m_bIsLeft && !FlagIsSet(nEndLine, LF_LEFT_ONLY)) ||
+                                       (m_bIsLeft && !FlagIsSet(nEndLine, LF_RIGHT_ONLY)))
+                       {
+                               CopyMemory(pszBuf, m_aLines[nEndLine].m_pcLine,
+                                       nEndChar * sizeof(TCHAR));
+                               pszBuf += nEndChar;
+                       }
+               }
+       }
+       else
+       {
+               // Skip blank diff lines
+               if ((!m_bIsLeft && !FlagIsSet(nStartLine, LF_LEFT_ONLY)) ||
+                               (m_bIsLeft && !FlagIsSet(nStartLine, LF_RIGHT_ONLY)))
+               {
+                       int nCount = nEndChar - nStartChar;
+                       CopyMemory(pszBuf, m_aLines[nStartLine].m_pcLine + nStartChar,
+                               nCount * sizeof(TCHAR));
+                       pszBuf += nCount;
+               }
+       }
+       pszBuf[0] = 0;
+       text.ReleaseBuffer();
+       text.FreeExtra();
+       return nBufSize;
+}
+
 BOOL CMergeDoc::CDiffTextBuffer::SafeWriteFile(HANDLE hFile, LPVOID lpBuf, DWORD dwLength)
 {
        DWORD dwWrittenBytes = 0;
index b3dd1ef..067ae92 100644 (file)
@@ -70,11 +70,15 @@ friend class CMergeDoc;
 private :
         CMergeDoc * m_pOwnerDoc;
                BOOL m_bIsLeft;
+               BOOL FlagIsSet(UINT line, DWORD flag);
+
            BOOL SafeWriteFile(HANDLE hFile, LPVOID lpBuf, DWORD dwLength);
                BOOL SafeReplaceFile(LPCTSTR pszReplaced, LPCTSTR pszReplacement);
 public :
              bool curUndoGroup();
              void ReplaceLine(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 SaveToFile (LPCTSTR pszFileName, 
                                                                                         int nCrlfStyle = CRLF_STYLE_AUTOMATIC , 
                                                                                         BOOL bClearModifiedFlag = TRUE );
index 749bea3..2528481 100644 (file)
@@ -319,7 +319,23 @@ void CMergeEditView::OnUpdateCurdiff(CCmdUI* pCmdUI)
 
 void CMergeEditView::OnEditCopy()
 {
-       CCrystalEditViewEx::Copy();
+       CMergeDoc * pDoc = GetDocument();
+       CPoint ptSelStart, ptSelEnd;
+       GetSelection(ptSelStart, ptSelEnd);
+       
+       // Nothing selected
+       if (ptSelStart == ptSelEnd)
+               return;
+
+       CString text;
+       if (m_bIsLeft)
+               pDoc->m_ltBuf.GetTextWithoutEmptys(ptSelStart.y, ptSelStart.x,
+                       ptSelEnd.y, ptSelEnd.x, text, m_bIsLeft);
+       else
+               pDoc->m_rtBuf.GetTextWithoutEmptys(ptSelStart.y, ptSelStart.x,
+                       ptSelEnd.y, ptSelEnd.x, text, m_bIsLeft);
+
+       PutToClipboard(text);
 }
 
 void CMergeEditView::OnUpdateEditCopy(CCmdUI* pCmdUI)
@@ -329,7 +345,37 @@ void CMergeEditView::OnUpdateEditCopy(CCmdUI* pCmdUI)
 
 void CMergeEditView::OnEditCut()
 {
-       CCrystalEditViewEx::Cut();
+       CPoint ptSelStart, ptSelEnd;
+       CMergeDoc * pDoc = GetDocument();
+       GetSelection(ptSelStart, ptSelEnd);
+
+       if ( ptSelStart == ptSelEnd )
+               return;
+
+       CString text;
+       if (m_bIsLeft)
+               pDoc->m_ltBuf.GetTextWithoutEmptys(ptSelStart.y, ptSelStart.x,
+                       ptSelEnd.y, ptSelEnd.x, text, m_bIsLeft);
+       else
+               pDoc->m_rtBuf.GetTextWithoutEmptys(ptSelStart.y, ptSelStart.x,
+                       ptSelEnd.y, ptSelEnd.x, text, m_bIsLeft);
+
+       PutToClipboard(text);
+
+       CPoint ptCursorPos = ptSelStart;
+       ASSERT_VALIDTEXTPOS(ptCursorPos);
+       SetAnchor(ptCursorPos);
+       SetSelection(ptCursorPos, ptCursorPos);
+       SetCursorPos(ptCursorPos);
+       EnsureVisible(ptCursorPos);
+
+       if (m_bIsLeft)
+               pDoc->m_ltBuf.DeleteText(this, ptSelStart.y, ptSelStart.x, ptSelEnd.y,
+                       ptSelEnd.x, CE_ACTION_CUT);
+       else
+               pDoc->m_rtBuf.DeleteText(this, ptSelStart.y, ptSelStart.x, ptSelEnd.y,
+                       ptSelEnd.x, CE_ACTION_CUT);
+
        m_pTextBuffer->SetModified(TRUE);
 }
 
index 7b464c0..c07d285 100644 (file)
@@ -1,3 +1,7 @@
+2003-03-31 Kimmo
+ PATCH: [ 711437 ] Don't copy/cut removed lines
+ WinMerge: MergeDoc.h MergeDoc.cpp MergeEditView.h MergeEditView.cpp
+
 2003-03-31 Perry
  PATCH: [ 712429 ] Fix UpdateItemStatus bug 712093
  WinMerge: DirActions.cpp DirView.cpp paths.cpp paths.h