55 CREATE_IF_NOT_FOUND_CURSOR ,
66 CREATE_IF_NOT_FOUND_TOP ,
77 FILE_NAME_FORMAT_SYNTAX ,
8+ MARKDOWN_FILE_EXTENSION_REGEX ,
89} from "../../constants" ;
910import { FileNameDisplayFormatter } from "../../formatters/fileNameDisplayFormatter" ;
1011import { FormatDisplayFormatter } from "../../formatters/formatDisplayFormatter" ;
@@ -338,6 +339,20 @@ export class CaptureChoiceBuilder extends ChoiceBuilder {
338339 return ;
339340 }
340341
342+ const selectedOption = nodeOptions . find (
343+ ( option ) => option . id === activeSelectionNodeId ,
344+ ) ;
345+ if ( ! selectedOption ) {
346+ new Notice (
347+ "Canvas nodes are still loading. Wait a moment and try again." ,
348+ ) ;
349+ return ;
350+ }
351+ if ( ! selectedOption . capturable ) {
352+ new Notice ( selectedOption . capturableReason ) ;
353+ return ;
354+ }
355+
341356 applyNodeId ( activeSelectionNodeId ) ;
342357 renderList ( filterInput . getValue ( ) ) ;
343358 } ) ;
@@ -357,6 +372,8 @@ export class CaptureChoiceBuilder extends ChoiceBuilder {
357372 title : string ;
358373 subtitle : string ;
359374 searchText : string ;
375+ capturable : boolean ;
376+ capturableReason : string ;
360377 } > = [ ] ;
361378
362379 const renderList = ( query : string ) => {
@@ -415,15 +432,25 @@ export class CaptureChoiceBuilder extends ChoiceBuilder {
415432 cls : "qa-canvas-node-item-actions" ,
416433 } ) ;
417434 const useButton = itemActions . createEl ( "button" , {
418- text : isSelected ? "Selected" : "Use node" ,
435+ text :
436+ isSelected && option . capturable
437+ ? "Selected"
438+ : option . capturable
439+ ? "Use node"
440+ : "Unavailable" ,
419441 } ) ;
420- if ( isSelected ) {
442+ if ( isSelected && option . capturable ) {
421443 useButton . addClass ( "mod-cta" ) ;
422444 }
423- useButton . addEventListener ( "click" , ( ) => {
424- applyNodeId ( option . id ) ;
425- renderList ( filterInput . getValue ( ) ) ;
426- } ) ;
445+ if ( ! option . capturable ) {
446+ useButton . setDisabled ( true ) ;
447+ useButton . title = option . capturableReason ;
448+ } else {
449+ useButton . addEventListener ( "click" , ( ) => {
450+ applyNodeId ( option . id ) ;
451+ renderList ( filterInput . getValue ( ) ) ;
452+ } ) ;
453+ }
427454
428455 const copyButton = itemActions . createEl ( "button" , {
429456 text : "Copy ID" ,
@@ -535,6 +562,8 @@ export class CaptureChoiceBuilder extends ChoiceBuilder {
535562 title : string ;
536563 subtitle : string ;
537564 searchText : string ;
565+ capturable : boolean ;
566+ capturableReason : string ;
538567 } > > {
539568 try {
540569 const raw = await this . app . vault . cachedRead ( canvasFile ) ;
@@ -594,11 +623,17 @@ export class CaptureChoiceBuilder extends ChoiceBuilder {
594623 title,
595624 subtitle,
596625 searchText : `${ node . id } ${ title } ${ subtitle } ` . toLowerCase ( ) ,
626+ capturable : true ,
627+ capturableReason : "" ,
597628 } ;
598629 }
599630
600631 if ( nodeType === "file" ) {
601632 const filePath = this . getCanvasNodeFilePath ( node . file ) ;
633+ const isMarkdownFile = MARKDOWN_FILE_EXTENSION_REGEX . test ( filePath ) ;
634+ const capturableReason = isMarkdownFile
635+ ? ""
636+ : "Canvas file cards must link to markdown files (.md)." ;
602637 const title = this . truncatePickerText (
603638 filePath . split ( "/" ) . pop ( ) ?? filePath ,
604639 90 ,
@@ -607,13 +642,18 @@ export class CaptureChoiceBuilder extends ChoiceBuilder {
607642 if ( coords ) {
608643 subtitleParts . push ( coords ) ;
609644 }
645+ if ( ! isMarkdownFile ) {
646+ subtitleParts . push ( "Not capturable in this version" ) ;
647+ }
610648 const subtitle = subtitleParts . join ( " · " ) ;
611649 return {
612650 id : node . id ,
613651 type : nodeType ,
614652 title,
615653 subtitle,
616654 searchText : `${ node . id } ${ title } ${ subtitle } ` . toLowerCase ( ) ,
655+ capturable : isMarkdownFile ,
656+ capturableReason,
617657 } ;
618658 }
619659
@@ -629,6 +669,8 @@ export class CaptureChoiceBuilder extends ChoiceBuilder {
629669 title,
630670 subtitle,
631671 searchText : `${ node . id } ${ title } ${ subtitle } ` . toLowerCase ( ) ,
672+ capturable : false ,
673+ capturableReason : "This Canvas node type is not capturable." ,
632674 } ;
633675 } ) ;
634676
0 commit comments