refactor: centralize multi-card bring-to-front logic and document new spatial workspace architecture.

This commit is contained in:
2025-11-26 17:52:14 +01:00
parent 835dcc4faa
commit 9a3ed74230
2 changed files with 34 additions and 7 deletions
+14 -1
View File
@@ -274,7 +274,6 @@ export class LayoutStore {
const dx = card.x - x;
const dy = card.y - y;
// Check if center is within inner radius of top card
// Use squared distance to avoid sqrt
const distSq = dx * dx + dy * dy;
if (distSq < radius * radius) {
@@ -296,6 +295,20 @@ export class LayoutStore {
.map(c => c.id);
}
bringToFront(ids: string[]) {
const cards = ids
.map(id => this.items.get(id))
.filter((c): c is LayoutCard => !!c);
// Sort by current Z-index to preserve relative order
cards.sort((a, b) => a.z - b.z);
// Assign new Z-indices
for (const card of cards) {
card.update({ z: this.zCounter++ });
}
}
getSnapshot() {
return Array.from(this.items.values()).map(card => card.toSnapshot());
}
+20 -6
View File
@@ -51,16 +51,30 @@ export const useCardPointer = (
if (state === 'drag-start') {
let effectiveSelection = selection;
if (!isSelected) {
onSelect([card.id], hasModifier);
if (hasModifier) {
effectiveSelection = [...selection, card.id];
} else {
if (!hasModifier) {
if (!isSelected) {
effectiveSelection = [card.id];
onSelect([card.id], false);
}
} else {
// Modifier pressed: Add card and stack to selection
const stackIds = card.store.getStackBelow(card);
const idsToAdd = new Set<string>();
if (!isSelected) idsToAdd.add(card.id);
stackIds.forEach(id => idsToAdd.add(id));
// Only select what isn't already selected to avoid toggling off
const unselectedIdsToAdd = Array.from(idsToAdd).filter(id => !selection.includes(id));
if (unselectedIdsToAdd.length > 0) {
onSelect(unselectedIdsToAdd, true);
effectiveSelection = [...selection, ...unselectedIdsToAdd];
}
}
card.bringToFront();
card.store.bringToFront(effectiveSelection);
setState('drag');