From 2f6c715c0590435288eed79863e54263883b4503 Mon Sep 17 00:00:00 2001 From: roberto Date: Wed, 15 May 2024 17:14:40 +0200 Subject: [PATCH] fix undo when there's a textAnnotation --- app/public/js/microdraw.js | 65 +++++++++++++++++++-------- app/public/js/tools/textAnnotation.js | 4 -- 2 files changed, 47 insertions(+), 22 deletions(-) diff --git a/app/public/js/microdraw.js b/app/public/js/microdraw.js index 231afc9..c36bf76 100644 --- a/app/public/js/microdraw.js +++ b/app/public/js/microdraw.js @@ -246,6 +246,13 @@ const Microdraw = (function () { return path; }, + _textFromJSON: (json) => { + const text = new paper.PointText(); + text.importJSON(json); + + return text; + }, + _selectRegionInList: function (reg) { // Select region name in list [].forEach.call(me.dom.querySelectorAll("#regionList > .region-tag"), function(r) { @@ -895,24 +902,46 @@ const Microdraw = (function () { me.region = null; for( let i = 0; i < undo.regions.length; i += 1 ) { const el = undo.regions[i]; - const path = me._pathFromJSON(el.json); - // add to the correct project activeLayer, which may not be the current one - paper.project.activeLayer.addChild(path); - - const reg = me.newRegion({ - name: el.name, - uid: el.uid, - path: path - }, undo.imageNumber); - - // here order matters: if fully selected is set after selected, partially selected paths will be incorrect - reg.path.fullySelected = el.fullySelected; - reg.path.selected = el.selected; - if( el.selected ) { - if( me.region === null ) { - me.region = reg; - } else { - console.log("WARNING: This should not happen. Are two regions selected?"); + + if (el.json[0] === 'Path' || el.json[0] === 'CompoundPath') { + const path = me._pathFromJSON(el.json); + // add to the correct project activeLayer, which may not be the current one + paper.project.activeLayer.addChild(path); + + const reg = me.newRegion({ + name: el.name, + uid: el.uid, + path: path + }, undo.imageNumber); + + // here order matters: if fully selected is set after selected, partially selected paths will be incorrect + reg.path.fullySelected = el.fullySelected; + reg.path.selected = el.selected; + if( el.selected ) { + if( me.region === null ) { + me.region = reg; + } else { + console.log("WARNING: This should not happen. Are two regions selected?"); + } + } + } + + if (el.json[0] === "PointText") { + const text = me._textFromJSON(el.json); + paper.project.activeLayer.addChild(text); + const reg = me.newRegion({ + name: "textAnnotation", + uid: el.uid, + path: text + }, undo.imageNumber); + reg.path.fullySelected = el.fullySelected; + reg.path.selected = el.selected; + if( el.selected ) { + if( me.region === null ) { + me.region = reg; + } else { + console.log("WARNING: This should not happen. Are two regions selected?"); + } } } } diff --git a/app/public/js/tools/textAnnotation.js b/app/public/js/tools/textAnnotation.js index 631aba6..8eb3e25 100644 --- a/app/public/js/tools/textAnnotation.js +++ b/app/public/js/tools/textAnnotation.js @@ -27,11 +27,7 @@ window.ToolTextAnnotation = {textAnnotation: (function() { fontWeight: 'normal' }); - // path.strokeWidth = Microdraw.config.defaultStrokeWidth; Microdraw.region = Microdraw.newRegion({path: text, name: 'textAnnotation'}); - // Microdraw.region.path.fillColor.alpha = 0; - // Microdraw.region.path.selected = true; - // Microdraw.commitMouseUndo(); const obj = dom.querySelector("#text-annotation-panel");