MCPcopy Create free account
hub / github.com/WinMerge/winmerge / CopyMultipleList

Method CopyMultipleList

Src/MergeDocDiffCopy.cpp:71–155  ·  view source on GitHub ↗

* @brief Copy range of diffs from one side to side. * This function copies given range of differences from side to another. * Ignored differences are skipped, and not copied. * @param [in] srcPane Source side from which diff is copied * @param [in] dstPane Destination side * @param [in] firstDiff First diff copied (0-based index) * @param [in] lastDiff Last diff copied (0-based index) */

Source from the content-addressed store, hash-verified

69 * @param [in] lastDiff Last diff copied (0-based index)
70 */
71void CMergeDoc::CopyMultipleList(int srcPane, int dstPane, int firstDiff, int lastDiff, int firstWordDiff, int lastWordDiff)
72{
73#ifdef _DEBUG
74 if (firstDiff > lastDiff)
75 _RPTF0(_CRT_ERROR, "Invalid diff range (firstDiff > lastDiff)!");
76 if (firstDiff < 0)
77 _RPTF0(_CRT_ERROR, "Invalid diff range (firstDiff < 0)!");
78 if (lastDiff > m_diffList.GetSize() - 1)
79 _RPTF0(_CRT_ERROR, "Invalid diff range (lastDiff < diffcount)!");
80#endif
81
82 lastDiff = (std::min)(m_diffList.GetSize() - 1, lastDiff);
83 firstDiff = (std::max)(0, firstDiff);
84 if (firstDiff > lastDiff)
85 return;
86
87 RescanSuppress suppressRescan(*this);
88
89 // Note we don't care about m_nDiffs count to become zero,
90 // because we don't rescan() so it does not change
91
92 SetCurrentDiff(lastDiff);
93
94 bool bGroupWithPrevious = false;
95 if (firstWordDiff <= 0 && lastWordDiff == -1)
96 {
97 if (!ListCopy(srcPane, dstPane, -1, bGroupWithPrevious, true))
98 return; // sync failure
99 }
100 else
101 {
102 if (!InlineDiffListCopy(srcPane, dstPane, lastDiff,
103 (firstDiff == lastDiff) ? firstWordDiff : 0, lastWordDiff, nullptr, bGroupWithPrevious, true))
104 return; // sync failure
105 }
106
107 SetEditedAfterRescan(dstPane);
108
109 int nGroup = GetActiveMergeView()->m_nThisGroup;
110 CMergeEditView* pViewDst = m_pView[nGroup][dstPane];
111 CEPoint currentPosDst{ 0, pViewDst->GetCursorPos().y };
112
113 CEPoint pt(0, 0);
114 pViewDst->SetCursorPos(pt);
115 pViewDst->SetNewSelection(pt, pt, false);
116 pViewDst->SetNewAnchor(pt);
117
118 // copy from bottom up is more efficient
119 for (int i = lastDiff - 1; i >= firstDiff; --i)
120 {
121 if (m_diffList.IsDiffSignificant(i))
122 {
123 SetCurrentDiff(i);
124 const DIFFRANGE* pdi = m_diffList.DiffRangeAt(i);
125 if (currentPosDst.y > pdi->dend)
126 {
127 if (pdi->blank[dstPane] >= 0)
128 currentPosDst.y -= pdi->dend - pdi->blank[dstPane] + 1;

Callers 1

OnX2YMethod · 0.80

Calls 4

IsDiffSignificantMethod · 0.80
DiffRangeAtMethod · 0.80
GetSizeMethod · 0.45
ClearMethod · 0.45

Tested by

no test coverage detected