MCPcopy Create free account
hub / github.com/ProgerXP/Notepad2e / Undo

Method Undo

scintilla/src/Document.cxx:888–971  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

886}
887
888int Document::Undo() {
889 int newPos = -1;
890 CheckReadOnly();
891 if ((enteredModification == 0) && (cb.IsCollectingUndo())) {
892 enteredModification++;
893 if (!cb.IsReadOnly()) {
894 bool startSavePoint = cb.IsSavePoint();
895 bool multiLine = false;
896 int steps = cb.StartUndo();
897 //Platform::DebugPrintf("Steps=%d\n", steps);
898 int coalescedRemovePos = -1;
899 int coalescedRemoveLen = 0;
900 int prevRemoveActionPos = -1;
901 int prevRemoveActionLen = 0;
902 for (int step = 0; step < steps; step++) {
903 const int prevLinesTotal = LinesTotal();
904 const Action &action = cb.GetUndoStep();
905 if (action.at == removeAction) {
906 NotifyModified(DocModification(
907 SC_MOD_BEFOREINSERT | SC_PERFORMED_UNDO, action));
908 } else if (action.at == containerAction) {
909 DocModification dm(SC_MOD_CONTAINER | SC_PERFORMED_UNDO);
910 dm.token = action.position;
911 NotifyModified(dm);
912 if (!action.mayCoalesce) {
913 coalescedRemovePos = -1;
914 coalescedRemoveLen = 0;
915 prevRemoveActionPos = -1;
916 prevRemoveActionLen = 0;
917 }
918 } else {
919 NotifyModified(DocModification(
920 SC_MOD_BEFOREDELETE | SC_PERFORMED_UNDO, action));
921 }
922 cb.PerformUndoStep();
923 if (action.at != containerAction) {
924 ModifiedAt(action.position);
925 newPos = action.position;
926 }
927
928 int modFlags = SC_PERFORMED_UNDO;
929 // With undo, an insertion action becomes a deletion notification
930 if (action.at == removeAction) {
931 newPos += action.lenData;
932 modFlags |= SC_MOD_INSERTTEXT;
933 if ((coalescedRemoveLen > 0) &&
934 (action.position == prevRemoveActionPos || action.position == (prevRemoveActionPos + prevRemoveActionLen))) {
935 coalescedRemoveLen += action.lenData;
936 newPos = coalescedRemovePos + coalescedRemoveLen;
937 } else {
938 coalescedRemovePos = action.position;
939 coalescedRemoveLen = action.lenData;
940 }
941 prevRemoveActionPos = action.position;
942 prevRemoveActionLen = action.lenData;
943 } else if (action.at == insertAction) {
944 modFlags |= SC_MOD_DELETETEXT;
945 coalescedRemovePos = -1;

Callers

nothing calls this directly

Calls 6

DocModificationClass · 0.85
StartUndoMethod · 0.80
PerformUndoStepMethod · 0.80
IsCollectingUndoMethod · 0.45
IsReadOnlyMethod · 0.45
IsSavePointMethod · 0.45

Tested by

no test coverage detected