Repository navigation
Adjust pinch event coordinates to container bounds - #57
hiroshisuga wants to merge 3 commits into
Conversation
they were not the best places to modify...
Refactor pinch handling to extract x and y coordinates after screen bounds adjustment.
|
The previous implementation (9c79af3) corrected the pinch origin in useGestureEvents.ts by converting the gesture origin from client coordinates to to those relative to the editor before dispatching the event. My investigation, however, showed that this changes the coordinate system of the dispatched input event itself and causes the editor offset to be applied twice when the input state is updated. The revised implementation (d77d455) keeps pinch event points in client space and applies the editor's screenBounds offset only where the pinch point is used for camera calculations in Editor.ts. This is also consistent with the upstream fix introduced in tldraw#2719. That PR explicitly treats event points as the coordinates within the client space, converts them relative to the editor (although the author said it "weird"), and applies the same conversion when calculating the pinch center for camera zooming. |
There was a problem hiding this comment.
🟡 Changes recommended
The offset pinch behavior needs a regression test before approval.
Get a fresh assessment by requesting another Copilot review.
Pull request overview
Fixes pinch-to-zoom positioning and responsiveness for offset editor containers.
Changes:
- Converts pinch origins from client to container-relative coordinates.
- Reduces the pinch detection threshold from 24px to 8px.
File summaries
| File | Description |
|---|---|
Editor.ts |
Corrects the pinch center used by camera calculations. |
useGestureEvents.ts |
Makes pinch zoom activate earlier. |
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 1
- Review effort level: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| const { screenBounds } = this.getInstanceState() | ||
| const x = info.point.x - screenBounds.x | ||
| const y = info.point.y - screenBounds.y |
|
Thanks for digging into this one, and especially for the follow-up comment explaining why the first I tested this on both supported lines, each built from source, with the patch applied to the
Both lines pin the same Short versionThe coordinate fix in The coordinate fix is rightConfirmed by instrumenting the running client on both lines. During a real two-finger pinch on the So the unpatched code feeds the raw client point into camera math that expects container coordinates, and Your choice to convert at the point of use rather than at the dispatch site is also the right one for
Converting inside I wrote the regression test this needs and ran it both ways: Full Measured end to endSame synthesized two-finger pinch, fingers held at the centre of the whiteboard container, identical
On 3.0 the fix lands the anchor within about 1 px of the fingers, which is the behaviour the issue asks Two honest caveats on these numbers. The unpatched drift is much smaller than the raw 520 px / 371 px Findings1. No test for this, and there is no pinch coverage at all (should fix)
Here is the test I used, if it helps. It fails on // packages/tldraw/src/test/commands/pinch.test.ts
import { TestEditor } from '../TestEditor'
let editor: TestEditor
beforeEach(() => {
editor = new TestEditor()
})
function pinch(focal: { x: number; y: number }, z: number) {
const base = { delta: { x: 0, y: 0 }, shiftKey: false, altKey: false, ctrlKey: false } as const
editor.dispatch({ type: 'pinch', name: 'pinch_start', point: { ...focal, z: 1 }, ...base })
editor.dispatch({ type: 'pinch', name: 'pinch', point: { ...focal, z }, ...base })
}
describe('When pinching', () => {
it('keeps the focal point anchored when the container is not offset', () => {
editor.setScreenBounds({ x: 0, y: 0, w: 1080, h: 720 })
const focal = { x: 400, y: 500 }
const before = editor.screenToPage(focal)
pinch(focal, 2)
const after = editor.screenToPage(focal)
expect(editor.getZoomLevel()).toBeCloseTo(2)
expect(after.x).toBeCloseTo(before.x)
expect(after.y).toBeCloseTo(before.y)
})
it('keeps the focal point anchored when the container is offset', () => {
editor.setScreenBounds({ x: 100, y: 200, w: 1080, h: 720 })
const focal = { x: 400, y: 500 }
const before = editor.screenToPage(focal)
pinch(focal, 2)
const after = editor.screenToPage(focal)
expect(editor.getZoomLevel()).toBeCloseTo(2)
expect(after.x).toBeCloseTo(before.x)
expect(after.y).toBeCloseTo(before.y)
})
})Heads up if you use the existing helpers instead: 2. The
|
| Build | During pinch |
|---|---|
| BBB 3.0 unpatched | ![]() |
| BBB 3.0 with this PR | ![]() |
| BBB 4.0 unpatched | ![]() |
| BBB 4.0 with this PR | ![]() |




In short, this PR fixes bigbluebutton/bigbluebutton#25661.
The pinch origin reported by the gesture handler is based on browser/client coordinates, while the camera expects coordinates relative to the tldraw container. When the tldraw container is offset from the browser viewport, this causes the zoom center to shift away from the midpoint between the two fingers.
This PR converts the pinch origin to container-relative coordinates by subtracting the container's left and top offsets.
It also reduces the distance threshold used to distinguish pinch zoom from two-finger panning from 24px to 8px. This makes pinch zoom respond earlier and reduces the initial delay and jump before zooming begins.
These changes make pinch-to-zoom use the expected point between the two fingers as its center and improve the responsiveness of the gesture in BigBlueButton.
And importantly, this PR is essentially a backport of tldraw#2719 , which was merged to the main stream code (perhaps at ver 2.0b) after we split up.
Change Type
patch— Bug fixminor— New featuremajor— Breaking changedependencies— Changes to package dependencies1documentation— Changes to the documentation only2tests— Changes to any test code only2internal— Any other changes that don't affect the published package2Footnotes
publishes a
patchrelease, for devDependencies useinternal↩will not publish a new version ↩ ↩2 ↩3