From 49cfd65493674139e58e51c16f0bc9812439b73e Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 13 Nov 2026 00:25:29 +0000 Subject: [PATCH] =?UTF-8?q?[204]=20Esc=20hebt=20die=20Auswahl=20nur=20auf,?= =?UTF-8?q?=20wenn=20sie=20seit=20Esc=20unver=C3=A4ndert=20ist=20(ein=20Kl?= =?UTF-8?q?ick=20unmittelbar=20nach=20Esc=20wurde=20vom=20verz=C3=B6gerten?= =?UTF-8?q?=20Esc=20wieder=20gel=C3=B6scht;=20E2E=20Layout-Blatt=20flacker?= =?UTF-8?q?te)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/state/escapeClear.test.ts | 28 ++++++++++++++++++++++++++++ src/state/useKeyboardShortcuts.ts | 20 ++++++++++++++++++-- 2 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 src/state/escapeClear.test.ts diff --git a/src/state/escapeClear.test.ts b/src/state/escapeClear.test.ts new file mode 100644 index 00000000..db442011 --- /dev/null +++ b/src/state/escapeClear.test.ts @@ -0,0 +1,28 @@ +import { describe, expect, it } from "vitest"; +import { clearSelectionAfterEscape } from "./useKeyboardShortcuts"; +import { EMPTY_SELECTION, fromIds, mergeSelection } from "./selection"; + +// [204] Esc hebt die Auswahl erst nach dem Ereignis auf; ein Klick unmittelbar nach Esc (E2E: Playwright +// sendet die Ereignisse ohne Pause) darf von diesem späten Esc nicht wieder gelöscht werden. +describe("clearSelectionAfterEscape", () => { + const line1 = mergeSelection(EMPTY_SELECTION, fromIds("drawings", ["a"])); + + it("hebt die Auswahl auf, wenn sie seit Esc unverändert ist", () => { + const calls: unknown[] = []; + expect(clearSelectionAfterEscape(line1, line1, (p) => calls.push(p))).toBe(true); + expect(calls).toHaveLength(1); + }); + + it("lässt eine seit Esc neu gewählte Auswahl stehen", () => { + const line2 = mergeSelection(EMPTY_SELECTION, fromIds("drawings", ["b"])); + const calls: unknown[] = []; + expect(clearSelectionAfterEscape(line1, line2, (p) => calls.push(p))).toBe(false); + expect(calls).toHaveLength(0); + }); + + it("tut bei leerer Auswahl nichts", () => { + const calls: unknown[] = []; + expect(clearSelectionAfterEscape(EMPTY_SELECTION, EMPTY_SELECTION, (p) => calls.push(p))).toBe(false); + expect(calls).toHaveLength(0); + }); +}); diff --git a/src/state/useKeyboardShortcuts.ts b/src/state/useKeyboardShortcuts.ts index 3ae4476c..55cbfec6 100644 --- a/src/state/useKeyboardShortcuts.ts +++ b/src/state/useKeyboardShortcuts.ts @@ -246,6 +246,22 @@ export function useActiveToolKeys( }, [activeTool]); } +/** + * Esc hebt die Auswahl erst nach dem Ereignis (Task) auf (s. u.). Wurde sie dazwischen geändert — z. B. ein + * Klick unmittelbar nach Esc —, gilt die neue Auswahl und nicht der längst vergangene Esc (sonst verschwindet + * die frisch gewählte Auswahl wieder). + */ +export function clearSelectionAfterEscape( + atKey: Selection, + current: Selection, + setSelection: (patch: Partial) => void, +): boolean { + if (current !== atKey) return false; + if (isEmpty(current, { withGroups: false })) return false; + setSelection(clearKinds()); + return true; +} + /** * Tastatur im Auswahl-Werkzeug: Ctrl/Cmd+A = alles auf der aktiven Ebene * wählen; Entf/Backspace = ALLE Selektierten (Wände + 2D-Elemente) löschen. @@ -285,10 +301,10 @@ export function useSelectAllAndDeleteShortcut(opts: { // (Esc gehört dann dem Dialog, die Auswahl dahinter bleibt wie in Archicad). if (e.key === "Escape" && !e.ctrlKey && !e.metaKey && !e.altKey) { if (document.querySelector("[aria-modal='true']")) return; + const atKey = getState().selection; setTimeout(() => { if (e.defaultPrevented) return; - if (isEmpty(opts.selection, { withGroups: false })) return; - setSelection(clearKinds()); + clearSelectionAfterEscape(atKey, getState().selection, setSelection); }); return; }