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 {
|
import {
|
||||||
|
useEffect,
|
||||||
useLayoutEffect,
|
useLayoutEffect,
|
||||||
useRef,
|
useRef,
|
||||||
type KeyboardEvent,
|
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
|
* 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), a
|
* scroll (the scroll margin then keeps the vertex clear of the strip, rev 4 M-1); after any
|
||||||
* pointer's or a finger's never moves the page under it.
|
* press of a pointer or a finger, anywhere, the page never moves under it.
|
||||||
*/
|
*/
|
||||||
function useLastInputKey() {
|
function useLastInputKey() {
|
||||||
const fromKey = useRef(false)
|
const fromKey = useRef(false)
|
||||||
const handlers = {
|
useEffect(() => {
|
||||||
onKeyDownCapture: () => {
|
const onPointer = () => {
|
||||||
fromKey.current = true
|
|
||||||
},
|
|
||||||
onPointerDownCapture: () => {
|
|
||||||
fromKey.current = false
|
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 () => {
|
it('a press on the interior keeps the focus on the handle that held the series', async () => {
|
||||||
await keyedVertex()
|
await keyedVertex()
|
||||||
const seen = watchCommitFocus()
|
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)
|
pressAt(marker('z'), 50, 50)
|
||||||
expect(seen[0]).toBe(vertex(1))
|
expect(seen[0]).toBe(vertex(1))
|
||||||
expect(document.activeElement).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 () => {
|
it('a press on « + » commits with the focus kept', async () => {
|
||||||
|
|||||||
Reference in new issue
Block a user