]> _ Git - fluidbook-toolbox.git/commitdiff
wait #5814 @2
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Mon, 20 Mar 2023 18:15:49 +0000 (19:15 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Mon, 20 Mar 2023 18:15:49 +0000 (19:15 +0100)
resources/linkeditor/js/linkeditor.js
resources/linkeditor/js/linkeditor.links.js
resources/linkeditor/js/linkeditor.undo.js

index 1577fc4fa9e3b71b35ddeb7d4385e2129bd1db29..0ad755f525de3ad1015c86d2cb826b319b1f1f72 100644 (file)
@@ -434,7 +434,7 @@ LinkEditor.prototype = {
         } else {
             page = this.utils.normalizePage(page);
         }
-        if (this.single) {
+        if (this.single || this.utils.isSpecialPage(page)) {
             return [page];
         }
         if (page % 2 === 1) {
index b5f0adc2c88ed95f0b61bbae5296e8120310e949..6b1f99cb2d594cb0dda0e0960c627a3548b22338 100644 (file)
@@ -592,17 +592,6 @@ LinkeditorLinks.prototype = {
         this.linkeditor.save.hasChanged();
     },
 
-    updateLinkData: function (id, data) {
-        if (LINKS[id] === undefined) {
-            console.warn('Link ' + id + ' not found');
-            return;
-        }
-        $.each(data, function (k, v) {
-            LINKS[id][k] = v;
-        });
-        this.linkeditor.rulers.updateMagnetValues();
-        this.updateLayers();
-    },
 
     startDragLink: function () {
         this.dragLinkPos = {x: this.linkeditor.mx, y: this.linkeditor.my};
@@ -982,8 +971,34 @@ LinkeditorLinks.prototype = {
                 $(this).attr('fb-' + d.side, center - parseFloat($(this).attr('fb-' + d.length)) / 2);
             });
         }
+        this.updateSelectionData([d.side]);
         this.linkeditor.hasChanged();
     },
+
+    updateLinkData: function (id, data) {
+        if (LINKS[id] === undefined) {
+            console.warn('Link ' + id + ' not found');
+            return;
+        }
+        $.each(data, function (k, v) {
+            LINKS[id][k] = v;
+        });
+        this.linkeditor.rulers.updateMagnetValues();
+        this.updateLayers();
+    },
+
+    updateSelectionData: function (props) {
+        this.getCurrentSelection().each(function () {
+            let uid = $(this).attr('fb-uid');
+            for (let i = 0; i < props.length; i++) {
+                let prop = props[i];
+                LINKS[uid][prop] = $(this).attr('fb-' + prop);
+            }
+        });
+        this.linkeditor.rulers.updateMagnetValues();
+        this.updateLayers();
+    },
+
     distributeSelection: function (axis) {
         let d = this.getMinMaxSelection(axis);
         let totalLength = d.max - d.min;
@@ -1003,6 +1018,7 @@ LinkeditorLinks.prototype = {
             $(link.link).attr('fb-' + d.side, s);
             s += link.length + space;
         });
+        this.updateSelectionData([d.side]);
         this.linkeditor.hasChanged();
     },
 
@@ -1068,10 +1084,27 @@ LinkeditorLinks.prototype = {
         let links = JSON.parse(state);
         this.clear();
         var $this = this;
+        var existingUIDs = [];
+        // Update existing and add new links
         $.each(links, function (k, link) {
             $this.addLink(link, false);
             LINKS[link.uid] = link;
+            existingUIDs.push(link.uid);
         });
+        // Search for missing links and delete them
+        var pages = this.linkeditor.getCurrentPages();
+        var currentPages = [];
+        $.each(pages, function (k, v) {
+            currentPages.push(v.toString());
+        })
+        $.each(LINKS, function (uid, link) {
+            if (currentPages.indexOf(link.page) >= 0) {
+                if (existingUIDs.indexOf(link.uid) === -1) {
+                    delete LINKS[uid];
+                }
+            }
+        });
+
         this.linkeditor.hasChanged(false);
     },
 };
index ca118f08ac3c3c9f2814a6181e25ff09711a3497..f2f73ded937e2da38cabfa97effb053165fd8cc7 100644 (file)
@@ -59,6 +59,7 @@ LinkeditorUndo.prototype = {
 
     pushState: function () {
         if (this.ignoreStatesChanges) {
+            console.log('ignore states changes');
             return;
         }
 
@@ -70,6 +71,7 @@ LinkeditorUndo.prototype = {
         let cs = this.linkeditor.links.getCurrentState();
         let ps = this.states[this.linkeditor.getCurrentPage()][index - 1];
         if (ps == cs) {
+            console.log('skipped : no change');
             return;
         }