Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 12 additions & 35 deletions browser_tests/tests/canvasSettings.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ test.describe('Canvas settings', { tag: '@canvas' }, () => {
/**
* Press left-mouse at canvas-relative `pos`, hold for `holdMs` (0 = no
* hold), nudge by `(dx, dy)` absolute pixels, then release. Spec-local
* because it exists only to probe the CanvasPointer timing thresholds.
* because it exists only to probe the CanvasPointer gesture thresholds.
*/
const holdDragAt = async (
comfyPage: ComfyPage,
Expand Down Expand Up @@ -422,54 +422,31 @@ test.describe('Canvas settings', { tag: '@canvas' }, () => {
})
})

test('ClickBufferTime governs the click-vs-drag time threshold', async ({
test('ClickBufferTime does not promote movement within drift', async ({
comfyPage
}) => {
// Keep drift generous so only elapsed time distinguishes click vs drag.
await comfyPage.settings.setSetting('Comfy.Pointer.ClickDrift', 20)
const node = (
await comfyPage.nodeOps.getNodeRefsByType('CLIPTextEncode')
)[0]
await comfyPage.settings.setSetting('Comfy.Pointer.ClickDrift', 6)
await comfyPage.settings.setSetting('Comfy.Pointer.ClickBufferTime', 0)
const titlePos = await node.getTitlePosition()
const NUDGE = 2
const HOLD_MS = 250
const before = await node.getPosition()

await test.step(`Buffer=2000ms (hold=${HOLD_MS}ms within buffer) → click, node stays put`, async () => {
await comfyPage.settings.setSetting(
'Comfy.Pointer.ClickBufferTime',
2000
)
const before = await node.getPosition()
await holdDragAt(comfyPage, titlePos, {
dx: NUDGE,
dy: NUDGE,
holdMs: HOLD_MS
})
const after = await node.getPosition()
expect(after.x).toBeCloseTo(before.x, 0)
expect(after.y).toBeCloseTo(before.y, 0)
await holdDragAt(comfyPage, titlePos, {
dx: 2,
dy: 0,
holdMs: 250
})

await test.step(`Buffer=50ms (hold=${HOLD_MS}ms exceeds buffer) → drag, node moves`, async () => {
await comfyPage.settings.setSetting('Comfy.Pointer.ClickBufferTime', 50)
const before = await node.getPosition()
await holdDragAt(comfyPage, titlePos, {
dx: NUDGE,
dy: NUDGE,
holdMs: HOLD_MS
})
const after = await node.getPosition()
expect(
Math.abs(after.x - before.x) + Math.abs(after.y - before.y)
).toBeGreaterThan(0)
})
const after = await node.getPosition()
expect(after.x).toBeCloseTo(before.x, 0)
expect(after.y).toBeCloseTo(before.y, 0)
})

test('ClickDrift governs the click-vs-drag distance threshold', async ({
comfyPage
}) => {
// Keep buffer generous so only drift distance matters.
await comfyPage.settings.setSetting('Comfy.Pointer.ClickBufferTime', 2000)
const node = (
await comfyPage.nodeOps.getNodeRefsByType('CLIPTextEncode')
)[0]
Expand Down
12 changes: 1 addition & 11 deletions browser_tests/tests/interaction.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,7 @@ test.describe('Node Interaction', () => {
// getNodeRefsByType order is non-deterministic, so identify by proximity.
const nodes = await comfyPage.nodeOps.getNodeRefsByType('CLIPTextEncode')
const togglerPos = DefaultGraphPositions.textEncodeNodeToggler
await comfyPage.settings.setSetting('Comfy.Pointer.DoubleClickTime', 0)
let targetNode = nodes[0]
let minDist = Infinity
for (const n of nodes) {
Expand All @@ -484,17 +485,6 @@ test.describe('Node Interaction', () => {
await expect(comfyPage.canvas).toHaveScreenshot(
'text-encode-toggled-off.png'
)
// Wait for the double-click window (300ms) to expire so the next
// click at the same position isn't interpreted as a double-click.
await expect
.poll(() =>
comfyPage.page.evaluate(() => {
const pointer = window.app!.canvas.pointer
if (!pointer.eLastDown) return true
return performance.now() - pointer.eLastDown.timeStamp > 300
})
)
.toBe(true)
await comfyPage.canvas.click({
position: togglerPos
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,6 @@ test.describe(

await expect(comfyPage.selectionToolbox).toBeVisible()
await expect(comfyPage.vueNodes.selectedNodes).toHaveCount(0)
test.fail(
true,
'FE-2040 / time-based promotion moves the group after 150 ms and 1 px of drift'
)
await expect.poll(() => groupBounds(comfyPage, 'Pair')).toEqual(before)
})

Expand Down
42 changes: 27 additions & 15 deletions docs/adr/CANVAS-GESTURE-0029-pointer-gesture-state-machine.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,12 @@ the interpretation of a gesture, and both renderers feed it.

- `idle` + `down` → `pressed`. Emits press-time commands such as
`bringToFront` and sticky selection for the right button.
- `pressed` + `move` within the drift threshold → `pressed`. Emits
`movePress`, which only the `CanvasPointer` adapter consumes (see
Compatibility requirements). The Vue adapter ignores it.
- `pressed` + `move` beyond the drift threshold → `dragging`. Emits
`startDrag` with the drag kind derived from the target and policy.
`startDrag` with the drag kind derived from the target and policy,
followed by `moveDrag` for the same event.
- `pressed` + `up` beyond the drift threshold → `idle`. Emits `startDrag`
followed by `endDrag`, even if no `move` arrived. It emits no click command
and does not replace the previous-click record.
Expand All @@ -111,19 +115,19 @@ the interpretation of a gesture, and both renderers feed it.
and any drop target.
- `pressed` + `cancel` → `idle`. Preserves the previous-click record and
emits no command.
- `dragging` + `cancel` → `idle`. Emits `cancelDrag`, which the
interpreter uses to release the drag, restore canvas flags, and release
pointer capture. This transition clears the previous-click record.
- `dragging` + `cancel` → `idle`. Preserves the previous-click record and
emits no command. During migration, `CanvasPointer.reset()` runs `finally`
and releases pointer capture.
- Any other pair returns the state unchanged with no commands.

2. **Commands are the only output.** The reducer returns plain, serializable
command values. They include `select`, `startDrag`, `moveDrag`, `endDrag`,
`openContextMenu`, `bringToFront`, and `marquee`. An interpreter applies them
to `selectionStore`, `layoutStore`, and canvas services. Nothing else writes
selection or drag state during a gesture. Existing node hooks and extension
callbacks are outward effects emitted by the interpreter in the required
order. This follows the command and effect distinction in
[State, effects and workflows](../guidance/state-and-effects.md).
command values. They include `select`, `startDrag`, `movePress`, `moveDrag`,
`endDrag`, `openContextMenu`, `bringToFront`, and `marquee`. An interpreter
applies them to `selectionStore`, `layoutStore`, and canvas services. Nothing
else writes selection or drag state during a gesture. Existing node hooks and
extension callbacks are outward effects emitted by the interpreter in the
required order. This follows the command and effect distinction in [State,
effects and workflows](../guidance/state-and-effects.md).
3. **Hit-test once per press.** The `down` event carries a `PointerTarget`
union (`canvas`, `node`, `nodeTitle`, `widget`, `slot`, `group`,
`groupTitle`, `reroute`, `link`, `linkCenter`, `resizeHandle`, and
Expand Down Expand Up @@ -169,12 +173,20 @@ the interpretation of a gesture, and both renderers feed it.
the first `moveDrag`, and no `moveDrag` fires inside the click threshold.
`CanvasPointer` currently invokes `onDrag` before `onDragStart` on the
promoting move and invokes `onDrag` for movement inside the threshold.
Characterization tests cover every current `onDrag` assignment and record
the reduced callback count.
Legacy `onDrag` consumers such as number-widget drag adjustment depend on
that in-threshold movement, so the `CanvasPointer` adapter forwards
`movePress` to `onDrag` while the Vue adapter ignores it. A number-widget
press that moves within the drift threshold can therefore adjust the value
and then open its prompt on release. Characterization
tests cover every current `onDrag` assignment and record the callback count.
- The adapter that accepts `down` owns the gesture until `up` or `cancel`.
Renderer, mode, and feature-flag changes take effect only after the gesture
returns to `idle`. Teardown, lost pointer capture, blur, and visibility loss
dispatch `cancel` to the current owner before ownership ends.
returns to `idle`. Teardown and lost pointer capture dispatch `cancel` to
the current owner before ownership ends. The browser releases capture
immediately after `pointerup` or `pointercancel`, so `lostpointercapture`
reports interruptions that deliver neither event. Window blur and
visibility listeners are added only if a browser is shown to end a gesture
without firing `lostpointercapture`.
- `CanvasPointer` remains exported with its current callback surface until
the corpus check shows no extension assigns any of `pointer.onClick`,
`pointer.onDoubleClick`, `pointer.onDragStart`, `pointer.onDrag`,
Expand Down
4 changes: 1 addition & 3 deletions src/lib/litegraph/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,8 @@ CanvasPointer replaces much of the original pointer handling code. It provides a

### Click "drift"

A small amount of buffering is performed between down/up events to prevent accidental micro-drag events. If either of the two controls are exceeded, the event will be considered a drag event, not a click.
A small amount of movement is tolerated between down/up events to prevent accidental micro-drag events. Once the pointer travels further than the limit, the event is considered a drag event, not a click. Time does not affect the decision.

- `bufferTime` is the maximum time that tiny movements can be ignored (Default: 32ms)
- `maxClickDrift` controls how far a click can drift from its down event before it is considered a drag (Default: 6)

### Double-click
Expand All @@ -57,7 +56,6 @@ When double clicking, the double click callback is executed shortly after one no
All above configuration is via class static.

```ts
CanvasPointer.bufferTime = 32
CanvasPointer.maxClickDrift = 6
CanvasPointer.doubleClickTime = 300
```
Expand Down
Loading
Loading