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.
This commit is contained in:
1 parent
462a22e74f
commit
303e153777
2 files changed
+19
-10
No files matched your search
@@ -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 } }
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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 () => {
|
||||
|
||||
Reference in new issue
Block a user