OSDN Git Service

when removing lines that have synchronization points,
authorTakashi Sawanaka <sdottaka@users.sourceforge.net>
Sun, 24 Apr 2016 02:36:36 +0000 (11:36 +0900)
committerTakashi Sawanaka <sdottaka@users.sourceforge.net>
Sun, 24 Apr 2016 02:36:36 +0000 (11:36 +0900)
delete paired synchronization points in other editor pane.

fixes #45

Src/DiffTextBuffer.cpp
Src/DiffTextBuffer.h
Src/GhostTextBuffer.cpp
Src/MergeDoc.cpp
Src/MergeDoc.h

index 8b66323..46d8d40 100644 (file)
@@ -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);
+}
index d5736e4..6268a59 100644 (file)
@@ -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);
 };
index 87f1e41..2a09c94 100644 (file)
@@ -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;
        }
 
index 76632b0..0a404a8 100644 (file)
@@ -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<std::vector<int> > CMergeDoc::GetSyncPointList()
 {
        std::vector<std::vector<int> > list;
+       if (!m_bHasSyncPoints)
+               return list;
        int idx[3] = {-1, -1, -1};
        std::vector<int> 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();
index 8568c50..d3120bc 100644 (file)
@@ -232,6 +232,7 @@ public:
        CChildFrame * GetParentFrame();
 
        void AddSyncPoint();
+       bool DeleteSyncPoint(int pane, int nLine, bool bRescan = true);
        void ClearSyncPoints();
        bool HasSyncPoints();
        std::vector<std::vector<int> > CMergeDoc::GetSyncPointList();