Skip to content

Commit

Permalink
Support aborting "Pick" mode in element picker
Browse files Browse the repository at this point in the history
This allows a user to go back to the previous selection after
entering interactive "Pick" mode.
  • Loading branch information
gorhill committed Mar 4, 2024
1 parent 0f4e50d commit a557f62
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
3 changes: 0 additions & 3 deletions src/css/epicker-ui.css
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions src/js/dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
13 changes: 10 additions & 3 deletions src/js/epicker-ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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);
Expand Down

0 comments on commit a557f62

Please sign in to comment.