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

Method ShowDiff

Src/MergeEditView.cpp:2522–2600  ·  view source on GitHub ↗

* @brief Scrolls to current diff and/or selects diff text * @param [in] bScroll If true scroll diff to view * @param [in] bSelectText If true select diff text * @note If bScroll and bSelectText are false, this does nothing! * @todo This shouldn't be called when no diff is selected, so * somebody could try to ASSERT(nDiff > -1)... */

Source from the content-addressed store, hash-verified

2520 * somebody could try to ASSERT(nDiff > -1)...
2521 */
2522void CMergeEditView::ShowDiff(bool bScroll, bool bSelectText)
2523{
2524 CMergeDoc *pd = GetDocument();
2525 const int nDiff = pd->GetCurrentDiff();
2526
2527 // Try to trap some errors
2528 if (nDiff >= pd->m_diffList.GetSize())
2529 _RPTF2(_CRT_ERROR, "Selected diff > diffcount (%d > %d)!",
2530 nDiff, pd->m_diffList.GetSize());
2531
2532 if (nDiff >= 0 && nDiff < pd->m_diffList.GetSize())
2533 {
2534 CEPoint ptStart, ptEnd;
2535 DIFFRANGE curDiff;
2536 pd->m_diffList.GetDiff(nDiff, curDiff);
2537
2538 ptStart.x = 0;
2539 ptStart.y = curDiff.dbegin;
2540 ptEnd.x = 0;
2541 ptEnd.y = curDiff.dend;
2542
2543 if (bScroll && !m_bDetailView)
2544 {
2545 if (!IsDiffVisible(curDiff, CONTEXT_LINES_BELOW))
2546 {
2547 // Difference is not visible, scroll it so that max amount of
2548 // scrolling is done while keeping the diff in screen. So if
2549 // scrolling is downwards, scroll the diff to as up in screen
2550 // as possible. This usually brings next diff to the screen
2551 // and we don't need to scroll into it.
2552 int nLine = GetSubLineIndex(ptStart.y);
2553 if (nLine > CONTEXT_LINES_ABOVE)
2554 {
2555 nLine -= CONTEXT_LINES_ABOVE;
2556 }
2557 GetGroupView(m_nThisPane)->ScrollToSubLine(nLine);
2558 for (int nPane = 0; nPane < pd->m_nBuffers; nPane++)
2559 {
2560 if (nPane != m_nThisPane)
2561 GetGroupView(nPane)->ScrollToSubLine(nLine);
2562 }
2563 }
2564
2565 vector<WordDiff> worddiffs;
2566 if (GetOptionsMgr()->GetBool(OPT_SCROLL_TO_FIRST_INLINE_DIFF))
2567 worddiffs = pd->GetWordDiffArrayInDiffBlock(nDiff);
2568 CEPoint pt = worddiffs.size() > 0 ?
2569 CEPoint{ worddiffs[0].begin[m_nThisPane], worddiffs[0].beginline[m_nThisPane] } :
2570 ptStart;
2571 GetGroupView(m_nThisPane)->SetCursorPos(pt);
2572 GetGroupView(m_nThisPane)->SetAnchor(pt);
2573 GetGroupView(m_nThisPane)->SetSelection(pt, pt);
2574 GetGroupView(m_nThisPane)->EnsureVisible(pt);
2575 for (int nPane = 0; nPane < pd->m_nBuffers; nPane++)
2576 {
2577 if (nPane != m_nThisPane)
2578 {
2579 if (worddiffs.size() > 0)

Callers

nothing calls this directly

Calls 11

GetLineLengthFunction · 0.85
GetCurrentDiffMethod · 0.80
GetDiffMethod · 0.80
SetSelectionMethod · 0.80
GetOptionsMgrFunction · 0.70
GetSizeMethod · 0.45
ScrollToSubLineMethod · 0.45
GetBoolMethod · 0.45
sizeMethod · 0.45
EnsureVisibleMethod · 0.45

Tested by

no test coverage detected