Skip to content

Commit d582bd9

Browse files
authored
Merge pull request #125 from rezailmi/rezailmi/add-toolbar-text-creation
Add toolbar text insertion and tighten text edit cleanup
2 parents fcb00cc + aa3de32 commit d582bd9

11 files changed

Lines changed: 728 additions & 28 deletions

src/panel.tsx

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ function DirectEditPanelContent() {
368368
handleMoveComplete,
369369
addComment, submitCommentDraft, addCommentReply, deleteComment, exportComment,
370370
sendCommentToAgent, setActiveCommentId,
371-
startTextEditing, toggleEditMode, deleteSelection,
371+
startTextEditing, toggleEditMode, deleteSelection, setCommentDraftText, setCommentDraftBlockedHandler,
372372
} = useDirectEditActions()
373373

374374
const {
@@ -399,7 +399,8 @@ function DirectEditPanelContent() {
399399

400400
React.useEffect(() => {
401401
commentDraftRef.current = ''
402-
}, [activeCommentId])
402+
setCommentDraftText('')
403+
}, [activeCommentId, setCommentDraftText])
403404

404405
const activeDraftComment = React.useMemo(() => {
405406
if (!commentTargetElement || !activeCommentId) return null
@@ -428,6 +429,21 @@ function DirectEditPanelContent() {
428429
))
429430
}, [])
430431

432+
React.useEffect(() => {
433+
if (!activeCommentId) {
434+
setCommentDraftBlockedHandler(null)
435+
return
436+
}
437+
438+
setCommentDraftBlockedHandler(() => {
439+
triggerCommentInputAttention(activeCommentId)
440+
})
441+
442+
return () => {
443+
setCommentDraftBlockedHandler(null)
444+
}
445+
}, [activeCommentId, setCommentDraftBlockedHandler, triggerCommentInputAttention])
446+
431447
const hasPendingCommentDraft = React.useCallback((nextCommentId: string | null = null) => {
432448
if (!activeCommentId) return false
433449
if (nextCommentId && nextCommentId === activeCommentId) return false
@@ -548,6 +564,7 @@ function DirectEditPanelContent() {
548564
comment={activeDraftComment}
549565
attentionNonce={commentInputAttention?.commentId === activeDraftComment.id ? commentInputAttention.nonce : 0}
550566
draftRef={commentDraftRef}
567+
onDraftTextChange={setCommentDraftText}
551568
onSubmit={(text) => submitCommentDraft(activeDraftComment.id, text)}
552569
onCancel={() => handleSetActiveComment(null)}
553570
/>,

src/panel/selected-comment-composer.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ export interface SelectedCommentComposerProps {
9292
comment: Comment
9393
attentionNonce: number
9494
draftRef?: React.MutableRefObject<string>
95+
onDraftTextChange?: (text: string) => void
9596
onSubmit: (text: string) => string | null
9697
onCancel: () => void
9798
}
@@ -100,6 +101,7 @@ export function SelectedCommentComposer({
100101
comment,
101102
attentionNonce,
102103
draftRef,
104+
onDraftTextChange,
103105
onSubmit,
104106
onCancel,
105107
}: SelectedCommentComposerProps) {
@@ -154,7 +156,8 @@ export function SelectedCommentComposer({
154156

155157
React.useEffect(() => {
156158
if (draftRef) draftRef.current = text
157-
}, [draftRef, text])
159+
onDraftTextChange?.(text)
160+
}, [draftRef, onDraftTextChange, text])
158161

159162
const submit = React.useCallback(() => {
160163
const nextText = text.trim()

0 commit comments

Comments
 (0)