@@ -42,6 +42,7 @@ export type ComposerCitationCommentRequest = {
4242export type ComposerCitationCommentTarget = {
4343 nodeKey : NodeKey ;
4444 sourceAnchor ?: AssistantCitationSourceAnchor ;
45+ removeOnCancel ?: boolean ;
4546} ;
4647
4748export const ComposerCitationCommentContext = createContext < {
@@ -68,7 +69,11 @@ export function $consumeComposerCitationCommentRequest(requestRef: {
6869 let offset = 0 ;
6970 for ( const node of paragraph . getChildren ( ) ) {
7071 if ( offset === request . citationStart && node instanceof ComposerCitationNode ) {
71- return { nodeKey : node . getKey ( ) , sourceAnchor : request . sourceAnchor } ;
72+ return {
73+ nodeKey : node . getKey ( ) ,
74+ sourceAnchor : request . sourceAnchor ,
75+ removeOnCancel : true ,
76+ } ;
7277 }
7378 offset += node . getTextContentSize ( ) ;
7479 }
@@ -78,6 +83,8 @@ export function $consumeComposerCitationCommentRequest(requestRef: {
7883function ComposerCitationDecorator ( props : { citation : AssistantCitation ; nodeKey : NodeKey } ) {
7984 const [ editor ] = useLexicalComposerContext ( ) ;
8085 const commentContext = use ( ComposerCitationCommentContext ) ;
86+ const commentTarget =
87+ commentContext . openComment ?. nodeKey === props . nodeKey ? commentContext . openComment : null ;
8188 const onSaveComment = ( comment : string ) : boolean => {
8289 if ( ! editor . isEditable ( ) ) return false ;
8390 let accepted = false ;
@@ -118,15 +125,13 @@ function ComposerCitationDecorator(props: { citation: AssistantCitation; nodeKey
118125 < AssistantCitationChip
119126 citation = { props . citation }
120127 commentEditor = { {
121- open : commentContext . openComment ?. nodeKey === props . nodeKey ,
122- sourceAnchor :
123- commentContext . openComment ?. nodeKey === props . nodeKey
124- ? commentContext . openComment . sourceAnchor
125- : undefined ,
128+ open : commentTarget !== null ,
129+ sourceAnchor : commentTarget ?. sourceAnchor ,
126130 onOpenChange : ( open ) => {
127131 if ( open && ! editor . isEditable ( ) ) return ;
128132 commentContext . onOpenChange ( props . nodeKey , open ) ;
129133 } ,
134+ ...( commentTarget ?. removeOnCancel ? { onCancel : onRemove } : { } ) ,
130135 onSave : onSaveComment ,
131136 onSaveAndSend : ( comment ) => {
132137 if ( ! onSaveComment ( comment ) ) return false ;
0 commit comments