refactor(editor): one press machine for clicks, drags and taps on the drawing

press.ts (pure: slop per pointer kind, nearest handle, press target, click
and drag actions, double click, stepPress) is now the editor canvas's only
decider; useCanvasGestures no longer uses clickHandler, useEmptyTap,
swallowClick nor useMoveGesture (deleted), and the box has no onClick.
canPan = dragAction(press target).type === 'pan' at pointer-down; framing
keys only when the box itself is the target. workStore.ts holds the U2
work with stale stamps: dropStale on every documentText change, reset on
a new session (editorStore subscription). The catalogue keeps useFraming
defaults and useEmptyTap, unchanged.

Named change (A13): a finger drag on a selected zone's (or circle link's)
interior moves nothing; the selected point is its own handle and still
moves by any pointer. Second observable change: touch and pen taps are
decided at the pointer-up from the press target, no longer from the
following click (no browser touch adjustment toward a marker).

tests/setup.ts: happy-dom has no elementsFromPoint; a shim answers the
pointerdown target and its ancestors.

Rewritten tests (editor-annotations-tab.test.tsx, D6b):
- "a touch tap deselects in its own click, not at the pointer-up" ->
  "a touch tap deselects at the pointer-up" (deselected after pointerup)
- "a touch tap whose click lands on a marker (adjustment) selects that
  marker" -> "a touch tap is decided by its press: a click adjusted toward
  a marker selects nothing" (deselected, announced, marker b not current)
- "a pen tap deselects in its own click, like a touch tap" -> "a pen tap
  deselects at the pointer-up, like a mouse tap"
- "a pen tap whose click lands on a marker selects that marker" -> "a pen
  tap is decided by its press: a click landing on a marker selects
  nothing"
Added: "a finger drags the selected point (its handle), never a selected
zone (A13)".
Drive-only changes, assertions unchanged: canvas fireEvent.click(x, y)
-> pressAt (pointerdown + pointerup) in the tab suite (C26, tracing,
paths, H3, H6, H8, filter reselect), editor-keep-alive and
editor-sections; drag moves carry buttons: 1 (C34, polygon block move,
H8 lostpointercapture and read-only, editor-no-loss drag in flight),
since a move without a button is a hover.
This commit is contained in:
bchanot committed 2026-11-17 16:56:35 +01:00
1 parent 5ca2b7e3ad
commit 08d266c89f
18 files changed
+1341 -311

No files matched your search

@@ -12,7 +12,7 @@ import {
useSelectionMark,
} from '@/editor/annotations/useCanvasBuild'
import { useCanvasGestures } from '@/editor/annotations/useCanvasGestures'
import type { MoveTarget } from '@/editor/annotations/useMoveGesture'
import type { MoveTarget } from '@/editor/annotations/useBlockDrag'
import type { ToolId } from '@/editor/annotations/uiState'
import { useT } from '@/i18n/useT'
import AnnotationOverlay, { type OverlayProps } from './AnnotationOverlay'
@@ -44,15 +44,20 @@ export interface AnnotationCanvasProps {
/**
* The edit canvas: the core's composed view, the numbers-only overlay above it in the
* same transformed box, the tool column beside it. Select and place work on `click`
* (a press that moved is a drag and swallows it); a drag from the selected marker moves
* it after 4 CSS px.
* same transformed box, the tool column beside it. Select and place work on a press
* released within the slop (the press machine, R-8); a drag past it moves the selection
* as a block: the selected point by any pointer, a shape's interior by mouse or pen (A13).
*/
export default function AnnotationCanvas(props: AnnotationCanvasProps) {
const overlay = useRef<SVGSVGElement | null>(null)
const viewport = useRef<HTMLDivElement | null>(null)
const build = useCanvasBuild(props.viewId)
const gestures = useCanvasGestures({ ...props, overlay, viewport })
const gestures = useCanvasGestures({
...props,
target: props.moveTarget,
overlay,
viewport,
})
useSelectionMark(build.host, props.selectedId, build.root)
useReportRoot(build.root, props.onRoot)
return (
@@ -326,7 +326,7 @@ function moveTargetOf(
) {
if (!selected || !model.measured || tool !== 'select') return null
return isEditable(selected.geometry)
? { id: selected.id, geometry: selected.geometry }
? { id: selected.id, kind: selected.kind, geometry: selected.geometry }
: null
}