@@ -324,6 +324,7 @@ export class CaptureChoiceBuilder extends ChoiceBuilder {
324324
325325 clearButton . addEventListener ( "click" , ( ) => {
326326 applyNodeId ( "" ) ;
327+ renderList ( filterInput . getValue ( ) ) ;
327328 } ) ;
328329
329330 useActiveSelectionButton . addEventListener ( "click" , ( ) => {
@@ -464,17 +465,19 @@ export class CaptureChoiceBuilder extends ChoiceBuilder {
464465 private getActiveCanvasSelectionNodeIdForPath (
465466 canvasPath : string ,
466467 ) : string | null {
467- const activeLeaf = this . app . workspace . activeLeaf as
468- {
469- view ?: {
470- getViewType ?: ( ) => string ;
471- file ?: { path ?: string } ;
472- canvas ?: {
473- selection ?: Set < { id ?: string } > ;
468+ const mostRecentLeaf = this . app . workspace . getMostRecentLeaf ?.( ) as
469+ | {
470+ view ?: {
471+ getViewType ?: ( ) => string ;
472+ file ?: { path ?: string } ;
473+ canvas ?: {
474+ selection ?: Set < { id ?: string } > ;
475+ } ;
474476 } ;
475- } ;
476- } | undefined ;
477- const view = activeLeaf ?. view ;
477+ }
478+ | null
479+ | undefined ;
480+ const view = mostRecentLeaf ?. view ;
478481 if ( ! view || view . getViewType ?.( ) !== "canvas" ) {
479482 return null ;
480483 }
@@ -550,8 +553,8 @@ export class CaptureChoiceBuilder extends ChoiceBuilder {
550553 ( node ) : node is {
551554 id : string ;
552555 type ?: string ;
553- text ?: string ;
554- file ?: string | { path ?: string } ;
556+ text ?: unknown ;
557+ file ?: unknown ;
555558 x ?: number ;
556559 y ?: number ;
557560 width ?: number ;
@@ -571,7 +574,8 @@ export class CaptureChoiceBuilder extends ChoiceBuilder {
571574
572575 const coords = this . describeCanvasNodeCoordinates ( node ) ;
573576 if ( nodeType === "text" ) {
574- const lines = ( node . text ?? "" )
577+ const rawText = typeof node . text === "string" ? node . text : "" ;
578+ const lines = rawText
575579 . split ( "\n" )
576580 . map ( ( line ) => line . trim ( ) )
577581 . filter ( ( line ) => line . length > 0 ) ;
@@ -594,10 +598,7 @@ export class CaptureChoiceBuilder extends ChoiceBuilder {
594598 }
595599
596600 if ( nodeType === "file" ) {
597- const filePath =
598- typeof node . file === "string"
599- ? node . file
600- : node . file ?. path ?? "(missing file path)" ;
601+ const filePath = this . getCanvasNodeFilePath ( node . file ) ;
601602 const title = this . truncatePickerText (
602603 filePath . split ( "/" ) . pop ( ) ?? filePath ,
603604 90 ,
@@ -616,7 +617,11 @@ export class CaptureChoiceBuilder extends ChoiceBuilder {
616617 } ;
617618 }
618619
619- const title = `Unsupported node (${ node . type ?? "unknown" } )` ;
620+ const nodeTypeLabel =
621+ typeof node . type === "string" && node . type . length > 0
622+ ? node . type
623+ : "unknown" ;
624+ const title = `Unsupported node (${ nodeTypeLabel } )` ;
620625 const subtitle = coords || "Type is not currently capturable" ;
621626 return {
622627 id : node . id ,
@@ -646,6 +651,23 @@ export class CaptureChoiceBuilder extends ChoiceBuilder {
646651 }
647652 }
648653
654+ private getCanvasNodeFilePath ( fileField : unknown ) : string {
655+ if ( typeof fileField === "string" ) {
656+ return fileField ;
657+ }
658+
659+ if (
660+ fileField &&
661+ typeof fileField === "object" &&
662+ "path" in fileField &&
663+ typeof ( fileField as { path ?: unknown } ) . path === "string"
664+ ) {
665+ return ( fileField as { path : string } ) . path ;
666+ }
667+
668+ return "(missing file path)" ;
669+ }
670+
649671 private describeCanvasNodeCoordinates ( node : {
650672 x ?: number ;
651673 y ?: number ;
0 commit comments