@@ -104,12 +104,15 @@ import {
104104import { Dialog , DialogContent , DialogFooter , Button } from ' ./ui' ;
105105
106106type LinkTab = ' url' | ' page' ;
107+ type LinkSource = ' annotation' | ' selection' ;
107108
108109interface Props {
109110 documentId: string ;
110111 isOpen? : boolean ;
111112 onClose? : () => void ;
112113 onExited? : () => void ;
114+ /** Source context that triggered the modal */
115+ source? : LinkSource ;
113116}
114117
115118const props = defineProps <Props >();
@@ -186,9 +189,10 @@ const handleSubmit = () => {
186189 };
187190 }
188191
189- // Create links based on context
190- if (selectedAnnotation .value ) {
191- // IRT-linked links from selected annotation
192+ // Helper to create link on annotation
193+ const createLinkOnAnnotation = () => {
194+ if (! selectedAnnotation .value ) return false ;
195+
192196 const anno = selectedAnnotation .value ;
193197 const rects = ' segmentRects' in anno .object ? anno .object .segmentRects : [anno .object .rect ];
194198
@@ -206,7 +210,13 @@ const handleSubmit = () => {
206210 strokeWidth: 2 ,
207211 });
208212 }
209- } else if (textSelection .value .length > 0 ) {
213+ return true ;
214+ };
215+
216+ // Helper to create link from text selection
217+ const createLinkFromSelection = () => {
218+ if (textSelection .value .length === 0 ) return false ;
219+
210220 const selectionText = selectionScope .value ?.getSelectedText ();
211221
212222 // Create transparent highlight parent with IRT-linked links for each selection
@@ -252,6 +262,20 @@ const handleSubmit = () => {
252262 }, ignore );
253263 }
254264 selectionScope .value ?.clear ();
265+ return true ;
266+ };
267+
268+ // Create links based on the source context passed when opening the modal
269+ // This ensures the correct context is used even when both annotation and text are selected
270+ if (props .source === ' annotation' ) {
271+ createLinkOnAnnotation ();
272+ } else if (props .source === ' selection' ) {
273+ createLinkFromSelection ();
274+ } else {
275+ // Fallback for backwards compatibility: annotation first, then selection
276+ if (! createLinkOnAnnotation ()) {
277+ createLinkFromSelection ();
278+ }
255279 }
256280
257281 props .onClose ?.();
0 commit comments