MCPcopy Create free account
hub / github.com/TortoiseGit/TortoiseGit / InsertText

Method InsertText

src/TortoiseMerge/BaseView.cpp:6612–6728  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6610}
6611
6612void CBaseView::InsertText(const CString& sText)
6613{
6614 ResetUndoStep();
6615
6616 POINT ptCaretViewPos = GetCaretViewPosition();
6617 int nLeft = ptCaretViewPos.x;
6618 int nViewLine = ptCaretViewPos.y;
6619
6620 if ((nViewLine == 0) && (GetViewCount() == 0))
6621 OnChar(VK_RETURN, 0, 0);
6622
6623 std::vector<CString> lines;
6624 int nStart = 0;
6625 int nEolPos = 0;
6626 while ((nEolPos = sText.Find('\r', nEolPos)) >= 0)
6627 {
6628 CString sLine = sText.Mid(nStart, nEolPos - nStart);
6629 lines.push_back(sLine);
6630 nEolPos++;
6631 nStart = nEolPos;
6632 }
6633 CString sLine = sText.Mid(nStart);
6634 lines.push_back(sLine);
6635
6636 int nLinesToPaste = static_cast<int>(lines.size());
6637 if (nLinesToPaste > 1)
6638 {
6639 // multiline text
6640
6641 // We want to undo the multiline insertion in a single step.
6642 CUndo::GetInstance().BeginGrouping();
6643
6644 sLine = GetViewLineChars(nViewLine);
6645 CString sLineLeft = sLine.Left(nLeft);
6646 CString sLineRight = sLine.Right(sLine.GetLength() - nLeft);
6647 EOL eOriginalEnding = GetViewLineEnding(nViewLine);
6648 viewdata newLine(L"", DiffState::Edited, 1, m_lineendings, HideState::Shown);
6649 if (!lines[0].IsEmpty() || !sLineRight.IsEmpty() || (eOriginalEnding != m_lineendings))
6650 {
6651 newLine.sLine = sLineLeft + lines[0];
6652 SetViewData(nViewLine, newLine);
6653 }
6654
6655 int nInsertLine = nViewLine;
6656 for (int i = 1; i < nLinesToPaste - 1; i++)
6657 {
6658 newLine.sLine = lines[i];
6659 InsertViewData(++nInsertLine, newLine);
6660 }
6661 newLine.sLine = lines[nLinesToPaste - 1] + sLineRight;
6662 newLine.ending = eOriginalEnding;
6663 InsertViewData(++nInsertLine, newLine);
6664
6665 SetModified();
6666 SaveUndoStep();
6667
6668 // adds new lines everywhere except me
6669 if (IsViewGood(m_pwndLeft) && m_pwndLeft != this)

Callers 4

HandleMenuItemClickMethod · 0.45
HandleMenuItemClickMethod · 0.45
HandleSnippetMethod · 0.45
OnBnClickedHistoryMethod · 0.45

Calls 9

OnCharFunction · 0.85
BeginGroupingMethod · 0.80
InsertViewEmptyLinesMethod · 0.80
EndGroupingMethod · 0.80
FindMethod · 0.45
sizeMethod · 0.45
GetLengthMethod · 0.45
IsEmptyMethod · 0.45
InsertMethod · 0.45

Tested by

no test coverage detected