Skip to content

Commit

Permalink
Fix issue #2499: Wrong line gets copied over when selecting text
Browse files Browse the repository at this point in the history
  • Loading branch information
sdottaka committed Nov 4, 2024
1 parent 5574efa commit c73bd25
Showing 1 changed file with 38 additions and 38 deletions.
76 changes: 38 additions & 38 deletions Src/MergeDocDiffCopy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -881,17 +881,13 @@ std::tuple<CEPoint, CEPoint, CEPoint, CEPoint> CMergeDoc::GetCharacterRange(int
{
if (ptStart.y < cd_dbegin)
{
ptSrcStart.x = 0;
ptSrcStart.y = cd_dbegin;
ptDstStart.x = 0;
ptDstStart.y = cd_dbegin;
ptSrcStart = { 0, cd_dbegin };
ptDstStart = ptSrcStart;
}
else
{
ptSrcStart.x = ptStart.x;
ptSrcStart.y = ptStart.y;
ptDstStart.x = ptStart.x;
ptDstStart.y = ptStart.y;
ptSrcStart = ptStart;
ptDstStart = ptStart;
if (srcPane == activePane)
{
if (ptDstStart.x > m_ptBuf[dstPane]->GetLineLength(ptDstStart.y))
Expand All @@ -906,35 +902,37 @@ std::tuple<CEPoint, CEPoint, CEPoint, CEPoint> CMergeDoc::GetCharacterRange(int
}
else
{
const int distance = GetDistance(*m_ptBuf[activePane], CEPoint{ worddiffs[firstWordDiff].end[activePane], worddiffs[firstWordDiff].endline[activePane] }, ptStart);
const auto& wdiffFirst = worddiffs[firstWordDiff];
const int distanceBegin = GetDistance(*m_ptBuf[activePane], CEPoint{ wdiffFirst.begin[activePane], wdiffFirst.beginline[activePane] }, ptStart);
const int distanceEnd = GetDistance(*m_ptBuf[activePane], CEPoint{ wdiffFirst.end[activePane], wdiffFirst.endline[activePane] }, ptStart);
if (srcPane == activePane)
{
ptDstStart = Advance(*m_ptBuf[dstPane], CEPoint{ worddiffs[firstWordDiff].end[dstPane], worddiffs[firstWordDiff].endline[dstPane] }, distance);
ptSrcStart.x = ptStart.x;
ptSrcStart.y = ptStart.y;
if (distanceBegin <= 0)
ptDstStart = { wdiffFirst.begin[dstPane], wdiffFirst.beginline[dstPane] };
else
ptDstStart = Advance(*m_ptBuf[dstPane], CEPoint{ wdiffFirst.end[dstPane], wdiffFirst.endline[dstPane] }, distanceEnd);
ptSrcStart = ptStart;
}
else
{
ptSrcStart = Advance(*m_ptBuf[srcPane], CEPoint{ worddiffs[firstWordDiff].end[srcPane], worddiffs[firstWordDiff].endline[srcPane] }, distance);
ptDstStart.x = ptStart.x;
ptDstStart.y = ptStart.y;
if (distanceBegin <= 0)
ptSrcStart = { wdiffFirst.begin[srcPane], wdiffFirst.beginline[srcPane] };
else
ptSrcStart = Advance(*m_ptBuf[srcPane], CEPoint{ wdiffFirst.end[srcPane], wdiffFirst.endline[srcPane] }, distanceEnd);
ptDstStart = ptStart;
}
}
if (lastWordDiff == -1)
{
if (ptEnd.y > cd_dend)
{
ptDstEnd.x = 0;
ptDstEnd.y = cd_dend + 1;
ptSrcEnd.x = 0;
ptSrcEnd.y = cd_dend + 1;
ptDstEnd = { 0, cd_dend + 1 };
ptSrcEnd = { 0, cd_dend + 1 };
}
else
{
ptDstEnd.x = ptEnd.x;
ptDstEnd.y = ptEnd.y;
ptSrcEnd.x = ptEnd.x;
ptSrcEnd.y = ptEnd.y;
ptDstEnd = ptEnd;
ptSrcEnd = ptEnd;
if (srcPane == activePane)
{
if (ptDstEnd.x > m_ptBuf[dstPane]->GetLineLength(ptDstEnd.y))
Expand All @@ -949,43 +947,45 @@ std::tuple<CEPoint, CEPoint, CEPoint, CEPoint> CMergeDoc::GetCharacterRange(int
}
else
{
const int distance = GetDistance(*m_ptBuf[activePane], CEPoint{ worddiffs[lastWordDiff].end[activePane], worddiffs[lastWordDiff].endline[activePane] }, ptEnd);
const auto& wdiffLast = worddiffs[lastWordDiff];
const int distanceBegin = GetDistance(*m_ptBuf[activePane], CEPoint{ wdiffLast.begin[activePane], wdiffLast.beginline[activePane] }, ptEnd);
const int distanceEnd = GetDistance(*m_ptBuf[activePane], CEPoint{ wdiffLast.end[activePane], wdiffLast.endline[activePane] }, ptEnd);
if (srcPane == activePane)
{
ptDstEnd = Advance(*m_ptBuf[dstPane], CEPoint{ worddiffs[lastWordDiff].end[dstPane], worddiffs[lastWordDiff].endline[dstPane] }, distance);
ptSrcEnd.x = ptEnd.x;
ptSrcEnd.y = ptEnd.y;
if (distanceBegin <= 0)
ptDstEnd = { wdiffLast.begin[dstPane], wdiffLast.beginline[dstPane] };
else
ptDstEnd = Advance(*m_ptBuf[dstPane], CEPoint{ wdiffLast.end[dstPane], wdiffLast.endline[dstPane] }, distanceEnd);
ptSrcEnd = ptEnd;
}
else
{
ptSrcEnd = Advance(*m_ptBuf[srcPane], CEPoint{ worddiffs[lastWordDiff].end[srcPane], worddiffs[lastWordDiff].endline[srcPane] }, distance);
ptDstEnd.x = ptEnd.x;
ptDstEnd.y = ptEnd.y;
if (distanceBegin <= 0)
ptSrcEnd = { wdiffLast.begin[srcPane], wdiffLast.beginline[srcPane] };
else
ptSrcEnd = Advance(*m_ptBuf[srcPane], CEPoint{ wdiffLast.end[srcPane], wdiffLast.endline[srcPane] }, distanceEnd);
ptDstEnd = ptEnd;
}
}
if (ptDstStart.y > cd_dend)
{
ptDstStart.x = 0;
ptDstStart.y = cd_dend + 1;
ptDstStart = { 0, cd_dend + 1 };
}
if (ptSrcStart.y > cd_dend)
{
ptSrcStart.x = 0;
ptSrcStart.y = cd_dend + 1;
ptSrcStart = { 0, cd_dend + 1 };
}
if (ptDstEnd.y < ptDstStart.y)
ptDstEnd.y = ptDstStart.y;
if (ptSrcEnd.y < ptSrcStart.y)
ptSrcEnd.y = ptSrcStart.y;
if (ptDstEnd.y > cd_dend)
{
ptDstEnd.x = 0;
ptDstEnd.y = cd_dend + 1;
ptDstEnd = { 0, cd_dend + 1 };
}
if (ptSrcEnd.y > cd_dend)
{
ptSrcEnd.x = 0;
ptSrcEnd.y = cd_dend + 1;
ptSrcEnd = { 0, cd_dend + 1 };
}

return std::make_tuple(ptSrcStart, ptSrcEnd, ptDstStart, ptDstEnd);
Expand Down

0 comments on commit c73bd25

Please sign in to comment.