mirror of
https://github.com/langgenius/dify.git
synced 2026-04-13 14:48:11 +08:00
fix comment cursor position
This commit is contained in:
parent
4653981b6b
commit
e8683bf957
@ -1,6 +1,5 @@
|
||||
import type { FC } from 'react'
|
||||
import { memo, useCallback, useEffect, useMemo, useState } from 'react'
|
||||
import { useReactFlow, useViewport } from 'reactflow'
|
||||
import { memo, useCallback, useEffect, useState } from 'react'
|
||||
import Avatar from '@/app/components/base/avatar'
|
||||
import { useAppContext } from '@/context/app-context'
|
||||
import { MentionInput } from './mention-input'
|
||||
@ -15,12 +14,6 @@ type CommentInputProps = {
|
||||
export const CommentInput: FC<CommentInputProps> = memo(({ position, onSubmit, onCancel }) => {
|
||||
const [content, setContent] = useState('')
|
||||
const { userProfile } = useAppContext()
|
||||
const { flowToScreenPosition } = useReactFlow()
|
||||
const viewport = useViewport()
|
||||
|
||||
const screenPosition = useMemo(() => {
|
||||
return flowToScreenPosition(position)
|
||||
}, [position.x, position.y, viewport.x, viewport.y, viewport.zoom, flowToScreenPosition])
|
||||
|
||||
useEffect(() => {
|
||||
const handleGlobalKeyDown = (e: KeyboardEvent) => {
|
||||
@ -46,8 +39,8 @@ export const CommentInput: FC<CommentInputProps> = memo(({ position, onSubmit, o
|
||||
<div
|
||||
className="absolute z-50 w-96"
|
||||
style={{
|
||||
left: screenPosition.x,
|
||||
top: screenPosition.y,
|
||||
left: position.x,
|
||||
top: position.y,
|
||||
}}
|
||||
data-comment-input
|
||||
>
|
||||
|
||||
@ -17,8 +17,8 @@ export const CommentCursor: FC<CommentCursorProps> = memo(({ mousePosition }) =>
|
||||
<div
|
||||
className="pointer-events-none absolute z-50 flex h-6 w-6 items-center justify-center"
|
||||
style={{
|
||||
left: mousePosition.elementX - 3,
|
||||
top: mousePosition.elementY - 3,
|
||||
left: mousePosition.elementX,
|
||||
top: mousePosition.elementY,
|
||||
transform: 'translate(-50%, -50%)',
|
||||
}}
|
||||
>
|
||||
|
||||
@ -68,9 +68,13 @@ export const useWorkflowComment = () => {
|
||||
}
|
||||
|
||||
try {
|
||||
// Convert screen position to flow position when submitting
|
||||
const { screenToFlowPosition } = reactflow
|
||||
const flowPosition = screenToFlowPosition({ x: pendingComment.x, y: pendingComment.y })
|
||||
|
||||
const newComment = await createWorkflowComment(appId, {
|
||||
position_x: pendingComment.x,
|
||||
position_y: pendingComment.y,
|
||||
position_x: flowPosition.x,
|
||||
position_y: flowPosition.y,
|
||||
content,
|
||||
mentioned_user_ids: mentionedUserIds,
|
||||
})
|
||||
@ -85,7 +89,7 @@ export const useWorkflowComment = () => {
|
||||
setPendingComment(null)
|
||||
setControlMode(ControlMode.Pointer)
|
||||
}
|
||||
}, [appId, pendingComment, setControlMode, setPendingComment, loadComments])
|
||||
}, [appId, pendingComment, setControlMode, setPendingComment, loadComments, reactflow])
|
||||
|
||||
const handleCommentCancel = useCallback(() => {
|
||||
setPendingComment(null)
|
||||
@ -270,18 +274,15 @@ export const useWorkflowComment = () => {
|
||||
activeCommentIdRef.current = null
|
||||
}, [setActiveComment, setActiveCommentId, setActiveCommentLoading])
|
||||
|
||||
const handleCreateComment = useCallback((mousePosition: { pageX: number; pageY: number }) => {
|
||||
const handleCreateComment = useCallback((mousePosition: { elementX: number; elementY: number }) => {
|
||||
if (controlMode === ControlMode.Comment) {
|
||||
const { screenToFlowPosition } = reactflow
|
||||
const flowPosition = screenToFlowPosition({ x: mousePosition.pageX, y: mousePosition.pageY })
|
||||
|
||||
console.log('Setting pending comment at flow position:', flowPosition)
|
||||
setPendingComment(flowPosition)
|
||||
console.log('Setting pending comment at screen position:', mousePosition)
|
||||
setPendingComment({ x: mousePosition.elementX, y: mousePosition.elementY })
|
||||
}
|
||||
else {
|
||||
console.log('Control mode is not Comment:', controlMode)
|
||||
}
|
||||
}, [controlMode, setPendingComment, reactflow])
|
||||
}, [controlMode, setPendingComment])
|
||||
|
||||
return {
|
||||
comments,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user