Skip to content

screenToFlowPosition and snapToGrid snaps mouse position when publishing Mouse Presence in multiplayer #3771

@Nick-Lucas

Description

@Nick-Lucas

When using Mouse Presence, we attach a mouse listener to the ReactFlow element and then need to transform the client coordinates to flow coordinates for dispatch. This requires the use of screenToFlowPosition

screenToFlowPosition though honours the snapToGrid config of the board, meaning the mouse cursor also gets snapped on all receiving clients

It would be helpful to have an escape hatch in screenToFlowPosition and flowToScreenPosition, so that the snapping config can be disabled

[screenToFlowPosition: (position: XYPosition) => {](

screenToFlowPosition: (position: XYPosition) => {
const { transform, snapToGrid, snapGrid, domNode } = store.getState();
if (!domNode) {
return position;
}
const { x: domX, y: domY } = domNode.getBoundingClientRect();
const correctedPosition = {
x: position.x - domX,
y: position.y - domY,
};
return pointToRendererPoint(correctedPosition, transform, snapToGrid, snapGrid || [1, 1]);
},
)

Something like this perhaps:

screenToFlowPosition: (position: XYPosition, opts: { snapToGrid?: boolean })

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions