From: Kimmo Varis Date: Mon, 31 Mar 2003 19:25:53 +0000 (+0000) Subject: PATCH: [ 711437 ] Don't copy/cut removed lines X-Git-Tag: 2.16.5~8065 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=238c47054b56d5e9ff1edc1bb55f49ae10a173f9;p=winmerge-jp%2Fwinmerge-jp.git PATCH: [ 711437 ] Don't copy/cut removed lines --- diff --git a/Src/MergeDoc.cpp b/Src/MergeDoc.cpp index bdca484ef..0a9a853e7 100644 --- a/Src/MergeDoc.cpp +++ b/Src/MergeDoc.cpp @@ -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; diff --git a/Src/MergeDoc.h b/Src/MergeDoc.h index b3dd1ef90..067ae925a 100644 --- a/Src/MergeDoc.h +++ b/Src/MergeDoc.h @@ -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 ); diff --git a/Src/MergeEditView.cpp b/Src/MergeEditView.cpp index 749bea39a..252848193 100644 --- a/Src/MergeEditView.cpp +++ b/Src/MergeEditView.cpp @@ -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); } diff --git a/Src/readme.txt b/Src/readme.txt index 7b464c00b..c07d285c7 100644 --- a/Src/readme.txt +++ b/Src/readme.txt @@ -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