From: Takashi Sawanaka Date: Sun, 24 Apr 2016 02:36:36 +0000 (+0900) Subject: when removing lines that have synchronization points, X-Git-Tag: 2.16.4+-jp-10~736 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=f7bd582c72eaec5205faa0c415b95d1fbfb8fd4f;p=winmerge-jp%2Fwinmerge-jp.git when removing lines that have synchronization points, delete paired synchronization points in other editor pane. fixes #45 --- diff --git a/Src/DiffTextBuffer.cpp b/Src/DiffTextBuffer.cpp index 8b6632305..46d8d403c 100644 --- a/Src/DiffTextBuffer.cpp +++ b/Src/DiffTextBuffer.cpp @@ -696,3 +696,17 @@ bool CDiffTextBuffer::curUndoGroup() { return (m_aUndoBuf.size() != 0 && m_aUndoBuf[0].m_dwFlags&UNDO_BEGINGROUP); } + +bool CDiffTextBuffer:: +DeleteText2(CCrystalTextView * pSource, int nStartLine, int nStartChar, + int nEndLine, int nEndChar, int nAction, bool bHistory /*=true*/) +{ + for (auto syncpnt : m_pOwnerDoc->GetSyncPointList()) + { + const int nLineSyncPoint = syncpnt[m_nThisPane]; + if (((nStartChar == 0 && nStartLine == nLineSyncPoint) || nStartLine < nLineSyncPoint) && + nLineSyncPoint < nEndLine) + m_pOwnerDoc->DeleteSyncPoint(m_nThisPane, nLineSyncPoint, false); + } + return CGhostTextBuffer::DeleteText2(pSource, nStartLine, nStartChar, nEndLine, nEndChar, nAction, bHistory); +} diff --git a/Src/DiffTextBuffer.h b/Src/DiffTextBuffer.h index d5736e451..6268a5994 100644 --- a/Src/DiffTextBuffer.h +++ b/Src/DiffTextBuffer.h @@ -76,4 +76,7 @@ public : void prepareForRescan(); virtual void OnNotifyLineHasBeenEdited(int nLine); bool IsInitialized() const; + virtual bool DeleteText2 (CCrystalTextView * pSource, int nStartLine, + int nStartPos, int nEndLine, int nEndPos, + int nAction = CE_ACTION_UNKNOWN, bool bHistory =true); }; diff --git a/Src/GhostTextBuffer.cpp b/Src/GhostTextBuffer.cpp index 87f1e41db..2a09c947e 100644 --- a/Src/GhostTextBuffer.cpp +++ b/Src/GhostTextBuffer.cpp @@ -317,7 +317,7 @@ Undo (CCrystalTextView * pSource, CPoint & ptCursorPos) GetTextWithoutEmptys (apparent_ptStartPos.y, apparent_ptStartPos.x, apparent_ptEndPos.y, apparent_ptEndPos.x, text, CRLF_STYLE_AUTOMATIC, false); if (text.GetLength() == ur.GetTextLength() && memcmp(text, ur.GetText(), text.GetLength() * sizeof(TCHAR)) == 0) { - VERIFY (CCrystalTextBuffer::DeleteText (pSource, + VERIFY (DeleteText (pSource, apparent_ptStartPos.y, apparent_ptStartPos.x, apparent_ptEndPos.y, apparent_ptEndPos.x, 0, false, false)); ptCursorPos = apparent_ptStartPos; @@ -363,7 +363,7 @@ Undo (CCrystalTextView * pSource, CPoint & ptCursorPos) else { int nEndLine, nEndChar; - VERIFY(CCrystalTextBuffer::InsertText (pSource, + VERIFY(InsertText (pSource, apparent_ptStartPos.y, apparent_ptStartPos.x, ur.GetText (), ur.GetTextLength (), nEndLine, nEndChar, 0, false)); ptCursorPos = m_ptLastChange; @@ -778,14 +778,14 @@ bool CGhostTextBuffer::DeleteText (CCrystalTextView * pSource, int nStartLine, nEndChar2 = 0; nEndLine2++; } - if (!CGhostTextBuffer::DeleteText2 (pSource, nStartLine2, nStartChar2, nEndLine2, nEndChar2, nAction, bHistory)) + if (!DeleteText2 (pSource, nStartLine2, nStartChar2, nEndLine2, nEndChar2, nAction, bHistory)) return false; } } } else { - if (!CGhostTextBuffer::DeleteText2 (pSource, nStartLine, nStartChar, nEndLine, nEndChar, nAction, bHistory)) + if (!DeleteText2 (pSource, nStartLine, nStartChar, nEndLine, nEndChar, nAction, bHistory)) return false; } diff --git a/Src/MergeDoc.cpp b/Src/MergeDoc.cpp index 76632b04b..0a404a86d 100644 --- a/Src/MergeDoc.cpp +++ b/Src/MergeDoc.cpp @@ -3330,18 +3330,17 @@ void CMergeDoc::OnToolsGeneratePatch() void CMergeDoc::AddSyncPoint() { int nLine[3]; - bool bRemovePreviousFromLine = false; for (int nBuffer = 0; nBuffer < m_nBuffers; ++nBuffer) { int tmp = m_pView[nBuffer]->GetCursorPos().y; nLine[nBuffer] = m_ptBuf[nBuffer]->ComputeApparentLine(m_ptBuf[nBuffer]->ComputeRealLine(tmp)); if (m_ptBuf[nBuffer]->GetLineFlags(nLine[nBuffer]) & LF_INVALID_BREAKPOINT) - bRemovePreviousFromLine = true; + DeleteSyncPoint(nBuffer, nLine[nBuffer], false); } for (int nBuffer = 0; nBuffer < m_nBuffers; ++nBuffer) - m_ptBuf[nBuffer]->SetLineFlag(nLine[nBuffer], LF_INVALID_BREAKPOINT, true, bRemovePreviousFromLine); + m_ptBuf[nBuffer]->SetLineFlag(nLine[nBuffer], LF_INVALID_BREAKPOINT, true, false); m_bHasSyncPoints = true; @@ -3352,6 +3351,29 @@ void CMergeDoc::AddSyncPoint() } /** + * @brief Delete a synchronization point + */ +bool CMergeDoc::DeleteSyncPoint(int pane, int nLine, bool bRescan) +{ + const auto syncpoints = GetSyncPointList(); + for (auto syncpnt : syncpoints) + { + if (syncpnt[pane] == nLine) + { + for (int nBuffer = 0; nBuffer < m_nBuffers; ++nBuffer) + m_ptBuf[nBuffer]->SetLineFlag(syncpnt[nBuffer], LF_INVALID_BREAKPOINT, false, false); + } + } + + if (syncpoints.size() == 1) + m_bHasSyncPoints = false; + + if (bRescan) + FlushAndRescan(true); + return true; +} + +/** * @brief Clear Synchronization points */ void CMergeDoc::ClearSyncPoints() @@ -3385,10 +3407,12 @@ bool CMergeDoc::HasSyncPoints() std::vector > CMergeDoc::GetSyncPointList() { std::vector > list; + if (!m_bHasSyncPoints) + return list; int idx[3] = {-1, -1, -1}; std::vector points(m_nBuffers); for (int nBuffer = 0; nBuffer < m_nBuffers; ++nBuffer) - points[nBuffer] = m_ptBuf[nBuffer]->GetLineCount() - 1; + points[nBuffer] = m_ptBuf[nBuffer]->GetLineCount() - 1; for (int nBuffer = 0; nBuffer < m_nBuffers; ++nBuffer) { int nLineCount = m_ptBuf[nBuffer]->GetLineCount(); diff --git a/Src/MergeDoc.h b/Src/MergeDoc.h index 8568c5038..d3120bc20 100644 --- a/Src/MergeDoc.h +++ b/Src/MergeDoc.h @@ -232,6 +232,7 @@ public: CChildFrame * GetParentFrame(); void AddSyncPoint(); + bool DeleteSyncPoint(int pane, int nLine, bool bRescan = true); void ClearSyncPoints(); bool HasSyncPoints(); std::vector > CMergeDoc::GetSyncPointList();