From 303e153777ec7207493c20baa448b73ef4ec3421 Mon Sep 17 00:00:00 2001 From: bchanot Date: Thu, 19 Nov 2026 15:18:04 +0100 Subject: [PATCH] fix(editor): any pointer press clears the keyboard scroll of a vertex The key flag only heard presses on the handle group: a press on the interior after a keyed series let the re-chosen vertex scroll the page under the pointer. Any pointerdown in the document now clears it. --- .../editor/annotations/ZoneHandles.tsx | 23 +++++++++++-------- apps/app/tests/unit/editor-zone-edit.test.tsx | 6 +++++ 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/apps/app/src/components/editor/annotations/ZoneHandles.tsx b/apps/app/src/components/editor/annotations/ZoneHandles.tsx index 99e7f979..9b19bfa4 100644 --- a/apps/app/src/components/editor/annotations/ZoneHandles.tsx +++ b/apps/app/src/components/editor/annotations/ZoneHandles.tsx @@ -1,4 +1,5 @@ import { + useEffect, useLayoutEffect, useRef, type KeyboardEvent, @@ -264,21 +265,23 @@ function focusIsOurs(group: SVGGElement, held: boolean): boolean { } /** - * Whether the group's last input was a key, read by the focus move: a key's focus may - * scroll (the scroll margin then keeps the vertex clear of the strip, rev 4 M-1), a - * pointer's or a finger's never moves the page under it. + * Whether the last input was a key on the group, read by the focus move: a key's focus may + * scroll (the scroll margin then keeps the vertex clear of the strip, rev 4 M-1); after any + * press of a pointer or a finger, anywhere, the page never moves under it. */ function useLastInputKey() { const fromKey = useRef(false) - const handlers = { - onKeyDownCapture: () => { - fromKey.current = true - }, - onPointerDownCapture: () => { + useEffect(() => { + const onPointer = () => { fromKey.current = false - }, + } + document.addEventListener('pointerdown', onPointer, true) + return () => document.removeEventListener('pointerdown', onPointer, true) + }, []) + const onKeyDownCapture = () => { + fromKey.current = true } - return { fromKey, handlers } + return { fromKey, handlers: { onKeyDownCapture } } } /** diff --git a/apps/app/tests/unit/editor-zone-edit.test.tsx b/apps/app/tests/unit/editor-zone-edit.test.tsx index 03db0b43..2f05cad9 100644 --- a/apps/app/tests/unit/editor-zone-edit.test.tsx +++ b/apps/app/tests/unit/editor-zone-edit.test.tsx @@ -1326,9 +1326,15 @@ describe('Safari: the focus after a press that commits a pending series', () => it('a press on the interior keeps the focus on the handle that held the series', async () => { await keyedVertex() const seen = watchCommitFocus() + // A pointer path never scrolls the page under the pointer, even after keys (rev 4 M-1). + const scrolls = vi + .spyOn(window.Element.prototype, 'scrollIntoView') + .mockImplementation(() => undefined) pressAt(marker('z'), 50, 50) expect(seen[0]).toBe(vertex(1)) expect(document.activeElement).toBe(vertex(1)) + expect(scrolls).not.toHaveBeenCalled() + scrolls.mockRestore() }) it('a press on « + » commits with the focus kept', async () => {