fix(editor): one press is either a pan or a click

useFraming takes an optional panning gate read on each one-pointer move;
the editor passes the press machine's drag-with-pan phase, so a zoomed
pen within its 6 px slop or a mouse wiggle no longer pans and clicks.
Catalogue: no options, behaviour unchanged.

Test added: « a press is either a pan or a click, never both (R-8) »
(pen 5 px clicks without pan, pen 8 px pans without click, mouse wiggle
clicks without pan). No assertion removed.
This commit is contained in:
bchanot committed 2026-11-17 17:10:45 +01:00
1 parent 35e4a4c75a
commit b2d78f9621
4 files changed
+83 -21

No files matched your search

@@ -1,6 +1,5 @@
import type { CSSProperties, KeyboardEvent, PointerEvent } from 'react'
import { useFraming } from '@/catalogue/useFraming'
import { dragAction, pointerKindOf } from './press'
import type { ToolId } from './uiState'
import { usePressGesture, type PressInput } from './usePressGesture'
@@ -60,15 +59,9 @@ function touchStyle(
export function useCanvasGestures(input: GestureInput) {
const press = usePressGesture(input)
const framing = useFraming(input.viewport, input.viewId, {
// A one-pointer pan only where the press machine would pan (a mouse or pen off the
// movable selection), decided once at pointer-down.
canPan: (event) =>
input.tool === 'select' &&
dragAction(press.target(), {
kind: pointerKindOf(event.pointerType),
movable: input.target !== null,
moveMode: false,
}).type === 'pan',
// The press machine decides: the drawing pans only while the press is a pan, so one
// press is either a pan or a click, never both (R-8).
panning: () => input.tool === 'select' && press.panning(),
})
const onKeyDown = (event: KeyboardEvent) => {
if (event.target !== event.currentTarget) return
@@ -120,7 +120,7 @@ function runClick(action: ClickAction, input: PressInput): void {
interface Machine {
press: Press
/** The press's target, read by the framing's pan decision at pointer-down. */
/** The press's target, kept for the capture decision at pointer-down. */
target: PressTarget
/** The pointers pressed on the box; one pressed outside it is never counted (no release). */
pointers: Set<number>
@@ -285,7 +285,7 @@ const IDLE: Press = { phase: 'idle' }
/**
* The editor's one decider for the drawing (U2 R-8): every pointer event goes through the
* press machine, whose effects select, deselect, place with a drawing tool, or move the
* selection as a block. `target()` is the press's target, for the framing's pan decision.
* selection as a block. `panning()` gates the framing's one-pointer pan.
*/
export function usePressGesture(input: PressInput) {
const drag = useBlockDrag(input)
@@ -306,7 +306,10 @@ export function usePressGesture(input: PressInput) {
const cancel = () => feed(latest.current, { type: 'cancel' }, null)
return {
preview: drag.preview,
target: () => machine.current.target,
panning: () => {
const press = machine.current.press
return press.phase === 'drag' && press.action.type === 'pan'
},
handlers: {
onPointerDown: (event: PointerEvent) => onPointerDown(latest, event),
onPointerMove: (event: PointerEvent) =>