Fix cursor chat bubble position. (#3042)

This PR fixes the position of the cursor chat bubble when the canvas is
not positioned at the top left.

### Change Type

- [x] `internal`

### Test Plan

1. Using CSS, add a margin left to the tldraw component on a multiplayer
route.
2. Use cursor chat.

### Release Notes

- Fixed a bug where cursor chat bubble position could be wrong when a
sidebar was open.

---------

Co-authored-by: Lu Wilson <l2wilson94@gmail.com>
This commit is contained in:
Steve Ruiz 2024-03-04 14:12:21 +00:00 committed by GitHub
parent 3c95ec1013
commit 08a2b59238
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -58,7 +58,11 @@ function usePositionBubble(ref: RefObject<HTMLInputElement>) {
// Positioning the chat bubble
function positionChatBubble(e: PointerEvent) {
ref.current?.style.setProperty('transform', `translate(${e.clientX}px, ${e.clientY}px)`)
const { minX, minY } = editor.getViewportScreenBounds()
ref.current?.style.setProperty(
'transform',
`translate(${e.clientX - minX}px, ${e.clientY - minY}px)`
)
}
window.addEventListener('pointermove', positionChatBubble)
@ -185,8 +189,6 @@ const CursorChatInput = track(function CursorChatInput({
)
const handlePaste = useCallback((e: ClipboardEvent) => {
// todo: figure out what's an acceptable / sanitized paste
preventDefault(e)
e.stopPropagation()
}, [])