From 6e60818136e3c016d9ca7f6ae74a13a99c9c0757 Mon Sep 17 00:00:00 2001 From: themancalledjakob Date: Fri, 22 Mar 2024 17:49:29 +0100 Subject: [PATCH] fix selection after deleting selected layer dependencies hashes: openFrameworks d78075f4bca6be2a2533c6e51a75cc1f18404501 ofxMsdfgen e14da13d02c4dff04fb69d7923469f606924e6c3 ofxGPUFont d482bb7cbdf6b296fa4ab5abcf73fb5ff8c8b239 ofxVariableLab 8df98846248a93aa068989a3ebd0d2f0f16e5e69 ofxProfiler a868e34fa1a79189dd4fbdede2938e308535e5e8 theatre 86d3e07f6f2c75fd6e08fca8c97e3617c9e23b18 --- bin/em/variabletime/web/js/artboard.js | 29 ++++++++++++++++++++++++++ bin/em/variabletime/web/js/main.js | 13 +++++++++--- 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/bin/em/variabletime/web/js/artboard.js b/bin/em/variabletime/web/js/artboard.js index 065f091..6638c30 100644 --- a/bin/em/variabletime/web/js/artboard.js +++ b/bin/em/variabletime/web/js/artboard.js @@ -173,6 +173,35 @@ const Artboard = function(tp, domElement = false, autoInit = true) { this.hide = () => { // 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 if (typeof domElement !== 'object') { diff --git a/bin/em/variabletime/web/js/main.js b/bin/em/variabletime/web/js/main.js index 95d8617..8268145 100644 --- a/bin/em/variabletime/web/js/main.js +++ b/bin/em/variabletime/web/js/main.js @@ -121,10 +121,7 @@ window.showAbout = () => { if (getAbout() === null) { return; } - getAbout().classList.remove("hidden"); - - } window.hideAbout = () => { if (getAbout() !== null) { @@ -524,9 +521,19 @@ const deleteLayer = (id, saveProject = true) => { } }); } + const wasSelected = layers[index].isSelected(); layers[index].prepareForDepartureFromThisBeautifulExperience(); layers.splice(index, 1); 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) { setTimeout(() => { tp.saveProject();