| 6610 | } |
| 6611 | |
| 6612 | void 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) |
no test coverage detected