From a557f6211244af96b52cba7da60e2d60afac328b Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Sun, 3 Mar 2024 20:08:15 -0500 Subject: [PATCH] Support aborting "Pick" mode in element picker This allows a user to go back to the previous selection after entering interactive "Pick" mode. --- src/css/epicker-ui.css | 3 --- src/js/dom.js | 4 ++-- src/js/epicker-ui.js | 13 ++++++++++--- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/css/epicker-ui.css b/src/css/epicker-ui.css index 6620e7179..01d3f05af 100644 --- a/src/css/epicker-ui.css +++ b/src/css/epicker-ui.css @@ -266,9 +266,6 @@ html#ublock0-epicker, height: 2em; width: 2em; } -#ublock0-epicker:not(.paused) #windowbar #minimize { - display: none; -} #windowbar #quit:hover, #windowbar #minimize:hover { background-color: var(--surface-2) diff --git a/src/js/dom.js b/src/js/dom.js index 3d2f517a2..5c4d19479 100644 --- a/src/js/dom.js +++ b/src/js/dom.js @@ -161,9 +161,9 @@ dom.cl = class { } } - static remove(target, name) { + static remove(target, ...names) { for ( const elem of normalizeTarget(target) ) { - elem.classList.remove(name); + elem.classList.remove(...names); } } diff --git a/src/js/epicker-ui.js b/src/js/epicker-ui.js index 00621718b..0c7ea1f5a 100644 --- a/src/js/epicker-ui.js +++ b/src/js/epicker-ui.js @@ -802,14 +802,16 @@ const showDialog = function(details) { /******************************************************************************/ const pausePicker = function() { - pickerRoot.classList.add('paused'); + dom.cl.add(pickerRoot, 'paused'); + dom.cl.remove(pickerRoot, 'minimized'); svgListening(false); }; /******************************************************************************/ const unpausePicker = function() { - pickerRoot.classList.remove('paused', 'preview'); + dom.cl.remove(pickerRoot, 'paused', 'preview'); + dom.cl.add(pickerRoot, 'minimized'); pickerContentPort.postMessage({ what: 'togglePreview', state: false, @@ -836,7 +838,12 @@ const startPicker = function() { $id('create').addEventListener('click', onCreateClicked); $id('pick').addEventListener('click', onPickClicked); $id('minimize').addEventListener('click', ( ) => { - dom.cl.toggle(dom.html, 'minimized'); + if ( dom.cl.has(pickerRoot, 'paused') === false ) { + pausePicker(); + onCandidateChanged(); + } else { + dom.cl.toggle(pickerRoot, 'minimized'); + } }); $id('quit').addEventListener('click', onQuitClicked); $id('move').addEventListener('mousedown', onStartMoving);