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

Method OnEditCopyLineNumbers

Src/MergeEditView.cpp:3620–3650  ·  view source on GitHub ↗

* @brief Copy selected lines adding linenumbers. */

Source from the content-addressed store, hash-verified

3618 * @brief Copy selected lines adding linenumbers.
3619 */
3620void CMergeEditView::OnEditCopyLineNumbers()
3621{
3622 CString strText;
3623 CString strLine;
3624 CString strNumLine;
3625
3626 CMergeDoc *pDoc = GetDocument();
3627 auto [ptStart, ptEnd] = GetSelection();
3628
3629 // Get last selected line (having widest linenumber)
3630 int line = pDoc->m_ptBuf[m_nThisPane]->ComputeRealLine(ptEnd.y);
3631 size_t nNumWidth = strutils::to_str(line + 1).length();
3632
3633 for (int i = ptStart.y; i <= ptEnd.y; i++)
3634 {
3635 if (GetLineFlags(i) & LF_GHOST || (GetEnableHideLines() && (GetLineFlags(i) & LF_INVISIBLE)))
3636 continue;
3637
3638 // We need to convert to real linenumbers
3639 line = pDoc->m_ptBuf[m_nThisPane]->ComputeRealLine(i);
3640
3641 // Insert spaces to align different width linenumbers (99, 100)
3642 strLine = GetLineText(i);
3643 CString sSpaces(' ', static_cast<int>(nNumWidth - strutils::to_str(line + 1).length()));
3644
3645 strText += sSpaces;
3646 strNumLine.Format(_T("%d: %s"), line + 1, (const tchar_t*)strLine);
3647 strText += strNumLine;
3648 }
3649 PutToClipboard(strText, strText.GetLength(), m_bRectangularSelection);
3650}
3651
3652void CMergeEditView::OnUpdateEditCopyLinenumbers(CCmdUI* pCmdUI)
3653{

Callers

nothing calls this directly

Calls 7

GetSelectionFunction · 0.85
GetEnableHideLinesFunction · 0.85
GetLengthMethod · 0.80
to_strFunction · 0.50
ComputeRealLineMethod · 0.45
lengthMethod · 0.45
FormatMethod · 0.45

Tested by

no test coverage detected