From 7ef494c7ddceb21dd057f483909f1e85b74dd40c Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Mon, 20 Mar 2023 19:15:49 +0100 Subject: [PATCH] wait #5814 @2 --- resources/linkeditor/js/linkeditor.js | 2 +- resources/linkeditor/js/linkeditor.links.js | 55 ++++++++++++++++----- resources/linkeditor/js/linkeditor.undo.js | 2 + 3 files changed, 47 insertions(+), 12 deletions(-) diff --git a/resources/linkeditor/js/linkeditor.js b/resources/linkeditor/js/linkeditor.js index 1577fc4fa..0ad755f52 100644 --- a/resources/linkeditor/js/linkeditor.js +++ b/resources/linkeditor/js/linkeditor.js @@ -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) { diff --git a/resources/linkeditor/js/linkeditor.links.js b/resources/linkeditor/js/linkeditor.links.js index b5f0adc2c..6b1f99cb2 100644 --- a/resources/linkeditor/js/linkeditor.links.js +++ b/resources/linkeditor/js/linkeditor.links.js @@ -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); }, }; diff --git a/resources/linkeditor/js/linkeditor.undo.js b/resources/linkeditor/js/linkeditor.undo.js index ca118f08a..f2f73ded9 100644 --- a/resources/linkeditor/js/linkeditor.undo.js +++ b/resources/linkeditor/js/linkeditor.undo.js @@ -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; } -- 2.39.5