MCPcopy Create free account
hub / github.com/RomanKubiak/ctrlr / remove

Method remove

JUCE/modules/juce_gui_extra/code_editor/juce_CodeDocument.cpp:1002–1060  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1000};
1001
1002void 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 }

Callers 15

addMethod · 0.45
subtractMethod · 0.45
clipToMethod · 0.45
consolidateMethod · 0.45
shortenSubPathFunction · 0.45
mergeAdjacentRangesFunction · 0.45
truncateFunction · 0.45
insertEllipsisMethod · 0.45
removeColourMethod · 0.45
timerCallbackMethod · 0.45
releaseUnusedImagesMethod · 0.45
removeListenerMethod · 0.45

Calls 11

jmaxFunction · 0.85
performMethod · 0.45
getUncheckedMethod · 0.45
substringMethod · 0.45
updateLengthMethod · 0.45
removeRangeMethod · 0.45
sizeMethod · 0.45
getPositionMethod · 0.45
setPositionMethod · 0.45
callMethod · 0.45

Tested by

no test coverage detected