{
const [dragging, setDragging] = React.useState(false)
const draggingCallback = React.useCallback((isDragging: boolean) => setDragging(isDragging), [])
- const { onMouseDown, didDrag, dragPosition } = useDragging(thread, location, draggingCallback)
+ const { onMouseDown: onMouseDownDrag, dragPosition } = useDragging(
+ thread,
+ location,
+ draggingCallback,
+ )
const remixLocationRoute = React.useMemo(() => {
return thread.metadata.remixLocationRoute ?? null
@@ -315,17 +298,6 @@ const CommentIndicator = React.memo(({ thread }: CommentIndicatorProps) => {
return remixLocationRoute != null && remixLocationRoute !== remixState?.location.pathname
}, [remixLocationRoute, remixState])
- const canvasScale = useEditorState(
- Substores.canvasOffset,
- (store) => store.editor.canvas.scale,
- 'CommentIndicator canvasScale',
- )
- const canvasOffset = useEditorState(
- Substores.canvasOffset,
- (store) => store.editor.canvas.roundedCanvasOffset,
- 'CommentIndicator canvasOffset',
- )
-
const isActive = useEditorState(
Substores.restOfEditor,
(store) =>
@@ -340,11 +312,6 @@ const CommentIndicator = React.memo(({ thread }: CommentIndicatorProps) => {
return !isActive && (hovered || dragging)
}, [hovered, isActive, dragging])
- const position = React.useMemo(
- () => canvasPointToWindowPoint(dragPosition ?? location, canvasScale, canvasOffset),
- [location, canvasScale, canvasOffset, dragPosition],
- )
-
const onMouseOut = React.useCallback(() => {
if (dragging) {
return
@@ -352,47 +319,53 @@ const CommentIndicator = React.memo(({ thread }: CommentIndicatorProps) => {
onHoverMouseOut()
}, [dragging, onHoverMouseOut])
- const onClick = React.useCallback(() => {
- if (didDrag) {
- return
- }
- if (isOnAnotherRoute && remixLocationRoute != null && remixState != null) {
- remixState.navigate(remixLocationRoute)
- }
- cancelHover()
- dispatch([
- ...openCommentThreadActions(thread.id, commentScene),
- setRightMenuTab(RightMenuTab.Comments),
- ])
- }, [
- dispatch,
- thread.id,
- remixState,
- remixLocationRoute,
- isOnAnotherRoute,
- commentScene,
- didDrag,
- cancelHover,
- ])
+ const onMouseDown = React.useCallback(
+ (e: React.MouseEvent) => {
+ onMouseDownDrag(e, (dragged) => {
+ if (dragged) {
+ return
+ }
+ if (isOnAnotherRoute && remixLocationRoute != null && remixState != null) {
+ remixState.navigate(remixLocationRoute)
+ }
+ cancelHover()
+ dispatch([
+ ...openCommentThreadActions(thread.id, commentScene),
+ setRightMenuTab(RightMenuTab.Comments),
+ ])
+ })
+ },
+ [
+ dispatch,
+ thread.id,
+ remixState,
+ remixLocationRoute,
+ isOnAnotherRoute,
+ commentScene,
+ cancelHover,
+ onMouseDownDrag,
+ ],
+ )
// This is a hack: when the comment is unread, we show a dark background, so we need light foreground colors.
// So we trick the Liveblocks Comment component and lie to it that the theme is dark mode.
const dataThemeProp = isRead ? {} : { 'data-theme': 'dark' }
+ const style = useIndicatorStyle(dragPosition ?? location, {
+ isRead: isRead,
+ resolved: thread.metadata.resolved,
+ isActive: isActive,
+ expanded: preview,
+ dragging: dragging,
+ })
+
return (
(null)
- const [didDrag, setDidDrag] = React.useState(false)
const canvasScaleRef = useRefEditorState((store) => store.editor.canvas.scale)
const canvasOffsetRef = useRefEditorState((store) => store.editor.canvas.roundedCanvasOffset)
@@ -463,9 +435,7 @@ function useDragging(
const remixSceneRoutesRef = useRefAtom(RemixNavigationAtom)
const onMouseDown = React.useCallback(
- (event: React.MouseEvent) => {
- setDidDrag(false)
-
+ (event: React.MouseEvent, onHandled: (dragged: boolean) => void) => {
const mouseDownPoint = windowPoint({ x: event.clientX, y: event.clientY })
const mouseDownCanvasPoint = windowToCanvasCoordinates(
canvasScaleRef.current,
@@ -494,7 +464,6 @@ function useDragging(
draggingCallback(true)
dispatch([switchEditorMode(EditorModes.commentMode(null, 'dragging'))])
- setDidDrag(true)
const dragVectorWindow = pointDifference(mouseDownPoint, mouseMovePoint)
const dragVectorCanvas = canvasPoint({
x: dragVectorWindow.x / canvasScaleRef.current,
@@ -508,10 +477,12 @@ function useDragging(
upEvent.stopPropagation()
window.removeEventListener('mousemove', onMouseMove)
window.removeEventListener('mouseup', onMouseUp)
- draggingCallback(false)
const mouseUpPoint = windowPoint({ x: upEvent.clientX, y: upEvent.clientY })
+ draggingCallback(false)
+ onHandled(draggedPastThreshold)
+
if (!draggedPastThreshold) {
return
}
@@ -588,7 +559,7 @@ function useDragging(
],
)
- return { onMouseDown, dragPosition, didDrag }
+ return { onMouseDown, dragPosition }
}
function useHover() {
diff --git a/editor/src/templates/editor-canvas.tsx b/editor/src/templates/editor-canvas.tsx
index 18eb910cd2e3..b6fc8fb300d8 100644
--- a/editor/src/templates/editor-canvas.tsx
+++ b/editor/src/templates/editor-canvas.tsx
@@ -299,7 +299,9 @@ function on(
}
if (isDragToPan(canvas.editorState.canvas.interactionSession, canvas.keysPressed['space'])) {
- if (event.event === 'MOVE' && event.nativeEvent.buttons === 1) {
+ const canPan =
+ !isFollowMode(canvas.mode) && event.event === 'MOVE' && event.nativeEvent.buttons === 1
+ if (canPan) {
return [
CanvasActions.scrollCanvas(
canvasPoint({
diff --git a/puppeteer-tests/src/comments/commenting.spec.tsx b/puppeteer-tests/src/comments/commenting.spec.tsx
index fe1af6f3dd14..3a4991c17713 100644
--- a/puppeteer-tests/src/comments/commenting.spec.tsx
+++ b/puppeteer-tests/src/comments/commenting.spec.tsx
@@ -236,8 +236,8 @@ describe('Comments test', () => {
expect(originalCommentIndicatorBoundingBox).toEqual({
height: 26,
width: 26,
- x: 485,
- y: 67,
+ x: 486,
+ y: 63,
})
// drag the comment on the scene