From 2c21530e3c4d189d6626777e0a9023be3962b3c9 Mon Sep 17 00:00:00 2001
From: Maximilian Giller <m.giller@tu-bs.de>
Date: Mon, 5 Sep 2022 00:22:27 +0200
Subject: [PATCH] Implements proper multilayerd use of storage disabling

---
 src/editor/js/structures/manageddata.ts | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/src/editor/js/structures/manageddata.ts b/src/editor/js/structures/manageddata.ts
index 65c6eeb..702dd86 100644
--- a/src/editor/js/structures/manageddata.ts
+++ b/src/editor/js/structures/manageddata.ts
@@ -16,7 +16,7 @@ export default class ManagedData extends SerializableItem {
     public history: SavePoint[]; // All save points of the data.
     public historyPosition: number; // Currently selected save point in history. Latest always at index 0.
     private savedHistoryId: number; // Id of save point that is considered saved.
-    private storingEnabled: boolean; // To internally disable saving of objects on save call.
+    private storingDisabled: number; // Storing is only enabled if this is 0 (or below).
 
     /**
      * Sets initial states.
@@ -28,7 +28,7 @@ export default class ManagedData extends SerializableItem {
         this.history = []; // Newest state is always at 0
         this.historyPosition = 0;
         this.savedHistoryId = 0;
-        this.storingEnabled = true;
+        this.storingDisabled = 0;
     }
 
     /**
@@ -88,14 +88,17 @@ export default class ManagedData extends SerializableItem {
      * Setter to disable storing save points.
      */
     public disableStoring() {
-        this.storingEnabled = false;
+        this.storingDisabled += 1;
     }
 
     /**
      * Setter to enable storing save points.
      */
     public enableStoring() {
-        this.storingEnabled = true;
+        this.storingDisabled -= 1;
+        if (this.storingDisabled < 0) {
+            this.storingDisabled = 0;
+        }
     }
 
     /**
@@ -217,7 +220,7 @@ export default class ManagedData extends SerializableItem {
      * @param relevantChanges Indicates major or minor changes. Major changes get a new id to indicate an actual changed state. Should usually be true.
      */
     public storeCurrentData(description: string, relevantChanges = true) {
-        if (this.storingEnabled === false) {
+        if (this.storingDisabled) {
             return;
         }
 
-- 
GitLab