| 1000 | }; |
| 1001 | |
| 1002 | void CodeDocument::remove (const int startPos, const int endPos, const bool undoable) |
| 1003 | { |
| 1004 | if (endPos <= startPos) |
| 1005 | return; |
| 1006 | |
| 1007 | if (undoable) |
| 1008 | { |
| 1009 | undoManager.perform (new DeleteAction (*this, startPos, endPos)); |
| 1010 | } |
| 1011 | else |
| 1012 | { |
| 1013 | Position startPosition (*this, startPos); |
| 1014 | Position endPosition (*this, endPos); |
| 1015 | |
| 1016 | maximumLineLength = -1; |
| 1017 | auto firstAffectedLine = startPosition.getLineNumber(); |
| 1018 | auto endLine = endPosition.getLineNumber(); |
| 1019 | auto& firstLine = *lines.getUnchecked (firstAffectedLine); |
| 1020 | |
| 1021 | if (firstAffectedLine == endLine) |
| 1022 | { |
| 1023 | firstLine.line = firstLine.line.substring (0, startPosition.getIndexInLine()) |
| 1024 | + firstLine.line.substring (endPosition.getIndexInLine()); |
| 1025 | firstLine.updateLength(); |
| 1026 | } |
| 1027 | else |
| 1028 | { |
| 1029 | auto& lastLine = *lines.getUnchecked (endLine); |
| 1030 | |
| 1031 | firstLine.line = firstLine.line.substring (0, startPosition.getIndexInLine()) |
| 1032 | + lastLine.line.substring (endPosition.getIndexInLine()); |
| 1033 | firstLine.updateLength(); |
| 1034 | |
| 1035 | int numLinesToRemove = endLine - firstAffectedLine; |
| 1036 | lines.removeRange (firstAffectedLine + 1, numLinesToRemove); |
| 1037 | } |
| 1038 | |
| 1039 | for (int i = firstAffectedLine + 1; i < lines.size(); ++i) |
| 1040 | { |
| 1041 | auto& l = *lines.getUnchecked (i); |
| 1042 | auto& previousLine = *lines.getUnchecked (i - 1); |
| 1043 | l.lineStartInFile = previousLine.lineStartInFile + previousLine.lineLength; |
| 1044 | } |
| 1045 | |
| 1046 | checkLastLineStatus(); |
| 1047 | auto totalChars = getNumCharacters(); |
| 1048 | |
| 1049 | for (auto* p : positionsToMaintain) |
| 1050 | { |
| 1051 | if (p->getPosition() > startPosition.getPosition()) |
| 1052 | p->setPosition (jmax (startPos, p->getPosition() + startPos - endPos)); |
| 1053 | |
| 1054 | if (p->getPosition() > totalChars) |
| 1055 | p->setPosition (totalChars); |
| 1056 | } |
| 1057 | |
| 1058 | listeners.call ([=] (Listener& l) { l.codeDocumentTextDeleted (startPos, endPos); }); |
| 1059 | } |
no test coverage detected