Skip to content

Commit

Permalink
fix undo when there's a textAnnotation
Browse files Browse the repository at this point in the history
  • Loading branch information
r03ert0 committed May 15, 2024
1 parent 4bf229c commit 2f6c715
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 22 deletions.
65 changes: 47 additions & 18 deletions app/public/js/microdraw.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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?");
}
}
}
}
Expand Down
4 changes: 0 additions & 4 deletions app/public/js/tools/textAnnotation.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down

0 comments on commit 2f6c715

Please sign in to comment.