@@ -49,13 +49,16 @@ type ModifyNodeFormProps = {
4949 /** DiscourseRelation.id; when set, relation is created with currentFile as the other end. */
5050 relationshipId ?: string ;
5151 relationshipTargetFile ?: TFile ;
52+ insertBacklink : boolean ;
5253 } ) => Promise < void > ;
5354 onCancel : ( ) => void ;
5455 initialTitle ?: string ;
5556 initialNodeType ?: DiscourseNode ;
5657 initialFile ?: TFile ; // for edit mode
5758 currentFile ?: TFile ; // the file where the node is being created from
5859 plugin : DiscourseGraphPlugin ;
60+ /** When true, show the insert-backlink checkbox (editor flows that honor insertBacklink). */
61+ showInsertBacklinkOption ?: boolean ;
5962} ;
6063
6164export const ModifyNodeForm = ( {
@@ -67,6 +70,7 @@ export const ModifyNodeForm = ({
6770 initialFile,
6871 currentFile,
6972 plugin,
73+ showInsertBacklinkOption = false ,
7074} : ModifyNodeFormProps ) => {
7175 const isEditMode = ! ! initialFile ;
7276 const [ title , setTitle ] = useState ( initialFile ?. basename || initialTitle ) ;
@@ -83,6 +87,7 @@ export const ModifyNodeForm = ({
8387 const [ selectedRelationshipKey , setSelectedRelationshipKey ] = useState <
8488 string | undefined
8589 > ( undefined ) ;
90+ const [ insertBacklink , setInsertBacklink ] = useState ( ! ! initialTitle ) ;
8691 const queryEngine = useRef ( new QueryEngine ( plugin . app ) ) ;
8792 const titleInputRef = useRef < HTMLTextAreaElement > ( null ) ;
8893 const popoverRef = useRef < HTMLDivElement > ( null ) ;
@@ -278,6 +283,7 @@ export const ModifyNodeForm = ({
278283 setSelectedExistingNode ( file ) ;
279284 setQuery ( file . basename ) ;
280285 setTitle ( file . basename ) ;
286+ setInsertBacklink ( true ) ;
281287 // Auto-detect node type from the selected file's frontmatter
282288 const nodeTypeId = await getNodeTypeIdForFile ( plugin , file ) ;
283289 if ( nodeTypeId && selectedFileRef . current === file ) {
@@ -291,12 +297,13 @@ export const ModifyNodeForm = ({
291297 const handleClearSelection = useCallback ( ( ) => {
292298 selectedFileRef . current = null ;
293299 setSelectedExistingNode ( null ) ;
300+ setInsertBacklink ( ! ! initialTitle ) ;
294301 setQuery ( "" ) ;
295302 setTitle ( "" ) ;
296303 setTimeout ( ( ) => {
297304 titleInputRef . current ?. focus ( ) ;
298305 } , 50 ) ;
299- } , [ ] ) ;
306+ } , [ initialTitle ] ) ;
300307
301308 const handleKeyDown = ( e : React . KeyboardEvent < HTMLTextAreaElement > ) => {
302309 if ( selectedExistingNode ) {
@@ -391,6 +398,7 @@ export const ModifyNodeForm = ({
391398 selectedExistingNode : selectedExistingNode || undefined ,
392399 relationshipId : selectedRel ?. uniqueKey || undefined ,
393400 relationshipTargetFile : currentFile || undefined ,
401+ insertBacklink,
394402 } ) ;
395403 onCancel ( ) ;
396404 } catch ( error ) {
@@ -418,6 +426,7 @@ export const ModifyNodeForm = ({
418426 selectedRelationshipKey ,
419427 currentFile ,
420428 availableRelationships ,
429+ insertBacklink ,
421430 ] ) ;
422431
423432 return (
@@ -568,6 +577,20 @@ export const ModifyNodeForm = ({
568577 </ div >
569578 ) }
570579
580+ { ! isEditMode && showInsertBacklinkOption && (
581+ < div className = "setting-item" >
582+ < div className = "setting-item-name" > Insert backlink</ div >
583+ < div className = "setting-item-control" >
584+ < input
585+ type = "checkbox"
586+ checked = { insertBacklink }
587+ onChange = { ( e ) => setInsertBacklink ( e . target . checked ) }
588+ disabled = { isSubmitting }
589+ />
590+ </ div >
591+ </ div >
592+ ) }
593+
571594 < div className = "modal-button-container mt-5 flex justify-end gap-2" >
572595 < button
573596 type = "button"
@@ -606,11 +629,13 @@ type ModifyNodeModalProps = {
606629 selectedExistingNode ?: TFile ;
607630 relationshipId ?: string ;
608631 relationshipTargetFile ?: TFile ;
632+ insertBacklink : boolean ;
609633 } ) => Promise < void > ;
610634 initialTitle ?: string ;
611635 initialNodeType ?: DiscourseNode ;
612636 initialFile ?: TFile ;
613637 currentFile ?: TFile ;
638+ showInsertBacklinkOption ?: boolean ;
614639} ;
615640
616641class ModifyNodeModal extends Modal {
@@ -622,13 +647,15 @@ class ModifyNodeModal extends Modal {
622647 selectedExistingNode ?: TFile ;
623648 relationshipId ?: string ;
624649 relationshipTargetFile ?: TFile ;
650+ insertBacklink : boolean ;
625651 } ) => Promise < void > ;
626652 private root : Root | null = null ;
627653 private initialTitle ?: string ;
628654 private initialNodeType ?: DiscourseNode ;
629655 private initialFile ?: TFile ;
630656 private currentFile ?: TFile ;
631657 private plugin : DiscourseGraphPlugin ;
658+ private showInsertBacklinkOption ?: boolean ;
632659
633660 constructor ( app : App , props : ModifyNodeModalProps ) {
634661 super ( app ) ;
@@ -639,6 +666,7 @@ class ModifyNodeModal extends Modal {
639666 this . initialFile = props . initialFile ;
640667 this . currentFile = props . currentFile ;
641668 this . plugin = props . plugin ;
669+ this . showInsertBacklinkOption = props . showInsertBacklinkOption ;
642670 }
643671
644672 onOpen ( ) {
@@ -657,6 +685,7 @@ class ModifyNodeModal extends Modal {
657685 initialFile = { this . initialFile }
658686 currentFile = { this . currentFile }
659687 plugin = { this . plugin }
688+ showInsertBacklinkOption = { this . showInsertBacklinkOption }
660689 />
661690 </ StrictMode > ,
662691 ) ;
0 commit comments