mirror of
https://github.com/gpxstudio/gpx.studio.git
synced 2025-09-02 00:32:33 +00:00
handle series of (de)select events together
This commit is contained in:
@@ -48,35 +48,44 @@
|
|||||||
let sortable: Sortable;
|
let sortable: Sortable;
|
||||||
let orientation = getContext<'vertical' | 'horizontal'>('orientation');
|
let orientation = getContext<'vertical' | 'horizontal'>('orientation');
|
||||||
|
|
||||||
|
let lastUpdateStart = 0;
|
||||||
function updateToSelection(e) {
|
function updateToSelection(e) {
|
||||||
if (updating) return;
|
lastUpdateStart = Date.now();
|
||||||
updating = true;
|
setTimeout(() => {
|
||||||
// Sortable updates selection
|
if (Date.now() - lastUpdateStart >= 40) {
|
||||||
let changed = getChangedIds();
|
if (updating) {
|
||||||
if (changed.length > 0) {
|
return;
|
||||||
selection.update(($selection) => {
|
|
||||||
$selection.clear();
|
|
||||||
Object.entries(elements).forEach(([id, element]) => {
|
|
||||||
$selection.set(
|
|
||||||
item.extend(getRealId(id)),
|
|
||||||
element.classList.contains('sortable-selected')
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
if (
|
|
||||||
e.originalEvent &&
|
|
||||||
$selection.size > 1 &&
|
|
||||||
!(e.originalEvent.ctrlKey || e.originalEvent.metaKey || e.originalEvent.shiftKey)
|
|
||||||
) {
|
|
||||||
// Fix bug that sometimes causes a single select to be treated as a multi-select
|
|
||||||
$selection.clear();
|
|
||||||
$selection.set(item.extend(getRealId(changed[0])), true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $selection;
|
updating = true;
|
||||||
});
|
// Sortable updates selection
|
||||||
}
|
let changed = getChangedIds();
|
||||||
updating = false;
|
if (changed.length > 0) {
|
||||||
|
selection.update(($selection) => {
|
||||||
|
$selection.clear();
|
||||||
|
Object.entries(elements).forEach(([id, element]) => {
|
||||||
|
$selection.set(
|
||||||
|
item.extend(getRealId(id)),
|
||||||
|
element.classList.contains('sortable-selected')
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
if (
|
||||||
|
e.originalEvent &&
|
||||||
|
$selection.size > 1 &&
|
||||||
|
!(e.originalEvent.ctrlKey || e.originalEvent.metaKey || e.originalEvent.shiftKey)
|
||||||
|
) {
|
||||||
|
// Fix bug that sometimes causes a single select to be treated as a multi-select
|
||||||
|
$selection.clear();
|
||||||
|
$selection.set(item.extend(getRealId(changed[0])), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $selection;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
updating = false;
|
||||||
|
}
|
||||||
|
}, 50);
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateFromSelection() {
|
function updateFromSelection() {
|
||||||
|
Reference in New Issue
Block a user