fix selection after deleting selected layer

dependencies hashes:
openFrameworks d78075f4bca6be2a2533c6e51a75cc1f18404501
ofxMsdfgen e14da13d02c4dff04fb69d7923469f606924e6c3
ofxGPUFont d482bb7cbdf6b296fa4ab5abcf73fb5ff8c8b239
ofxVariableLab 8df98846248a93aa068989a3ebd0d2f0f16e5e69
ofxProfiler a868e34fa1a79189dd4fbdede2938e308535e5e8
theatre 86d3e07f6f2c75fd6e08fca8c97e3617c9e23b18
This commit is contained in:
themancalledjakob 2024-03-22 17:49:29 +01:00
parent 6ec94b4beb
commit 6e60818136
2 changed files with 39 additions and 3 deletions

View file

@ -173,6 +173,35 @@ const Artboard = function(tp, domElement = false, autoInit = true) {
this.hide = () => { this.hide = () => {
// nothing to do // nothing to do
}; };
const getHierarchyPanelButton = () => {
if (hierarchyPanelButton === null) {
hierarchyPanelButton = tp.shadowRoot.querySelector(`.layerMover${this.id()}`);
}
return hierarchyPanelButton;
};
this.isSelected = () => {
const panel = getHierarchyPanelButton();
if (panel === null) {
return false;
} else {
const notSelected = panel.querySelector('.not-selected');
return !notSelected;
}
};
this.select = () => {
const panel = getHierarchyPanelButton();
const selectables = panel.querySelector('.not-selected');
if (selectables !== null && typeof selectables.dispatchEvent === 'function') {
var clickEvent = new MouseEvent("click", {
"view": window,
"bubbles": true,
"cancelable": false
});
selectables.dispatchEvent(clickEvent);
} else {
window.debugElement = panel;
}
};
// action // action
if (typeof domElement !== 'object') { if (typeof domElement !== 'object') {

View file

@ -121,10 +121,7 @@ window.showAbout = () => {
if (getAbout() === null) { if (getAbout() === null) {
return; return;
} }
getAbout().classList.remove("hidden"); getAbout().classList.remove("hidden");
} }
window.hideAbout = () => { window.hideAbout = () => {
if (getAbout() !== null) { if (getAbout() !== null) {
@ -524,9 +521,19 @@ const deleteLayer = (id, saveProject = true) => {
} }
}); });
} }
const wasSelected = layers[index].isSelected();
layers[index].prepareForDepartureFromThisBeautifulExperience(); layers[index].prepareForDepartureFromThisBeautifulExperience();
layers.splice(index, 1); layers.splice(index, 1);
delete layersById[id]; delete layersById[id];
if (wasSelected) {
if (layers.length > index + 1) {
layers[index].select();
} else if (layers.length > 0) {
layers[layers.length - 1].select();
} else {
artboard.select();
}
}
if (saveProject) { if (saveProject) {
setTimeout(() => { setTimeout(() => {
tp.saveProject(); tp.saveProject();