feat: mouse right click can add new comment

This commit is contained in:
hjlarry
2026-01-29 09:13:12 +08:00
parent 0495dc5085
commit 26dd6c128c
31 changed files with 160 additions and 15 deletions

View File

@ -7,14 +7,25 @@ const CommentManager = () => {
const { handleCreateComment, handleCommentCancel } = useWorkflowComment()
useEventListener('click', (e) => {
const { controlMode, mousePosition, pendingComment } = workflowStore.getState()
const { controlMode, mousePosition, pendingComment, isCommentPlacing } = workflowStore.getState()
const target = e.target as HTMLElement
const isInDropdown = target.closest('[data-mention-dropdown]')
const isInCommentInput = target.closest('[data-comment-input]')
const isOnCanvasPane = target.closest('.react-flow__pane')
if (isCommentPlacing) {
if (!isInDropdown && !isInCommentInput && isOnCanvasPane) {
e.preventDefault()
e.stopPropagation()
workflowStore.setState({
pendingComment: mousePosition,
isCommentPlacing: false,
})
}
return
}
if (controlMode === 'comment') {
const target = e.target as HTMLElement
const isInDropdown = target.closest('[data-mention-dropdown]')
const isInCommentInput = target.closest('[data-comment-input]')
const isOnCanvasPane = target.closest('.react-flow__pane')
// Only when clicking on the React Flow canvas pane (background),
// and not inside comment input or its dropdown
if (!isInDropdown && !isInCommentInput && isOnCanvasPane) {
@ -28,6 +39,16 @@ const CommentManager = () => {
}
})
useEventListener('contextmenu', () => {
const { isCommentPlacing } = workflowStore.getState()
if (!isCommentPlacing)
return
workflowStore.setState({
isCommentPlacing: false,
isCommentQuickAdd: false,
})
})
return null
}