// Reine Mehrfachauswahl-Logik (Akzeptanzkriterium 3: Umschalt- und // Strg-Taste) — unabhängig von React/DOM testbar. export interface SelectionState { selected: Set; anchorIndex: number | null; // letzter "einfacher" Klick, Basis fuer Umschalt-Bereiche } export function initialSelection(): SelectionState { return { selected: new Set(), anchorIndex: null }; } export interface ClickModifiers { shiftKey: boolean; ctrlOrMetaKey: boolean; } // applyClick bildet das aus Dateimanagern bekannte Verhalten nach: // - einfacher Klick: genau dieses Element auswaehlen, neuer Anker // - Strg/Cmd+Klick: dieses Element zur Auswahl hinzufuegen/entfernen (toggle) // - Umschalt+Klick: zusammenhaengenden Bereich vom Anker bis hierher waehlen export function applyClick( state: SelectionState, ids: string[], clickedIndex: number, modifiers: ClickModifiers ): SelectionState { const clickedID = ids[clickedIndex]; if (modifiers.shiftKey && state.anchorIndex !== null) { const [from, to] = [state.anchorIndex, clickedIndex].sort((a, b) => a - b); const range = ids.slice(from, to + 1); return { selected: new Set(range), anchorIndex: state.anchorIndex }; } if (modifiers.ctrlOrMetaKey) { const next = new Set(state.selected); if (next.has(clickedID)) { next.delete(clickedID); } else { next.add(clickedID); } return { selected: next, anchorIndex: clickedIndex }; } return { selected: new Set([clickedID]), anchorIndex: clickedIndex }; } export function isSelected(state: SelectionState, id: string): boolean { return state.selected.has(id); } export function clearSelection(state: SelectionState): SelectionState { return { selected: new Set(), anchorIndex: null }; }