@@ -463,65 +463,103 @@ function initNoteAutocomplete($el: JQuery<HTMLElement>, options?: Options) {
463463
464464 // TODO: Types fail due to "autocomplete:selected" not being registered in type definitions.
465465 ( $el as any ) . on ( "autocomplete:selected" , async ( event : Event , suggestion : Suggestion ) => {
466+ $el . setSelectedNotePath ( suggestion . notePath ) ;
467+ $el . setSelectedExternalLink ( null ) ;
468+ $el . autocomplete ( "val" , suggestion . noteTitle ) ;
469+
466470 switch ( suggestion . action ) {
467471 case SuggestionAction . Command : {
468- $el . autocomplete ( "close" ) ;
469- $el . trigger ( "autocomplete:commandselected" , [ suggestion ] ) ;
470472 break ;
471473 }
472474
473475 case SuggestionAction . ExternalLink : {
474- $el . setSelectedNotePath ( null ) ;
475- $el . setSelectedExternalLink ( suggestion . externalLink ) ;
476- $el . autocomplete ( "val" , suggestion . externalLink ) ;
477- $el . autocomplete ( "close" ) ;
478- $el . trigger ( "autocomplete:externallinkselected" , [ suggestion ] ) ;
479476 break ;
480477 }
481478
482- case SuggestionAction . CreateNoteIntoInbox :
483- case SuggestionAction . CreateAndLinkNoteIntoInbox : {
479+ // --- CREATE NOTE INTO INBOX ---
480+ case SuggestionAction . CreateNoteIntoInbox : {
484481 const { note } = await noteCreateService . createNote (
485482 {
486483 target : "inbox" ,
487484 title : suggestion . noteTitle ,
488485 activate : true ,
489486 promptForType : true ,
490- } as CreateNoteIntoInboxOpts
487+ }
491488 ) ;
492489
493- if ( ! note ) return ;
490+ if ( ! note )
491+ break ;
494492
495493 const hoistedNoteId = appContext . tabManager . getActiveContext ( ) ?. hoistedNoteId ;
496494 suggestion . notePath = note ?. getBestNotePathString ( hoistedNoteId ) ;
497-
498- $el . trigger ( "autocomplete:noteselected" , [ suggestion ] ) ;
499- $el . autocomplete ( "close" ) ;
500495 break ;
501496 }
502497
503- case SuggestionAction . CreateNoteIntoPath :
504- case SuggestionAction . CreateAndLinkNoteIntoPath : {
505- if ( ! suggestion . parentNoteId ) return ;
498+ case SuggestionAction . CreateAndLinkNoteIntoInbox : {
499+ const { note } = await noteCreateService . createNote (
500+ {
501+ target : "inbox" ,
502+ title : suggestion . noteTitle ,
503+ activate : false ,
504+ promptForType : true ,
505+ }
506+ ) ;
507+
508+ if ( ! note )
509+ break ;
510+
511+ const hoistedNoteId = appContext . tabManager . getActiveContext ( ) ?. hoistedNoteId ;
512+ suggestion . notePath = note ?. getBestNotePathString ( hoistedNoteId ) ;
513+
514+ $el . autocomplete ( "close" ) ;
515+ $el . trigger ( "autocomplete:noteselected" , [ suggestion ] ) ;
516+ return ;
517+ }
506518
519+ case SuggestionAction . CreateNoteIntoPath : {
520+ if ( ! suggestion . parentNoteId ) {
521+ console . warn ( "Missing parentNoteId for CreateNoteIntoPath" ) ;
522+ return ;
523+ }
507524 const { note } = await noteCreateService . createNote (
508525 {
509- parentNoteUrl : suggestion . parentNoteId ,
510526 target : "into" ,
527+ parentNoteUrl : suggestion . parentNoteId ,
511528 title : suggestion . noteTitle ,
512529 activate : true ,
513530 promptForType : true ,
514531 } ,
515532 ) ;
516533
517- if ( ! note ) return ;
534+ if ( ! note ) break ;
518535
519536 const hoistedNoteId = appContext . tabManager . getActiveContext ( ) ?. hoistedNoteId ;
520537 suggestion . notePath = note ?. getBestNotePathString ( hoistedNoteId ) ;
538+ break ;
539+ }
521540
522- $el . trigger ( "autocomplete:noteselected" , [ suggestion ] ) ;
541+ case SuggestionAction . CreateAndLinkNoteIntoPath : {
542+ if ( ! suggestion . parentNoteId ) {
543+ console . warn ( "Missing parentNoteId for CreateNoteIntoPath" ) ;
544+ return ;
545+ }
546+ const { note } = await noteCreateService . createNote (
547+ {
548+ target : "into" ,
549+ parentNoteUrl : suggestion . parentNoteId ,
550+ title : suggestion . noteTitle ,
551+ activate : false ,
552+ promptForType : true ,
553+ }
554+ ) ;
555+
556+ if ( ! note ) break ;
557+
558+ const hoistedNoteId = appContext . tabManager . getActiveContext ( ) ?. hoistedNoteId ;
559+ suggestion . notePath = note ?. getBestNotePathString ( hoistedNoteId ) ;
523560 $el . autocomplete ( "close" ) ;
524- break ;
561+ $el . trigger ( "autocomplete:noteselected" , [ suggestion ] ) ;
562+ return ;
525563 }
526564
527565 case SuggestionAction . SearchNotes : {
@@ -531,13 +569,12 @@ function initNoteAutocomplete($el: JQuery<HTMLElement>, options?: Options) {
531569 }
532570
533571 default : {
534- $el . setSelectedNotePath ( suggestion . notePath ) ;
535- $el . setSelectedExternalLink ( null ) ;
536- $el . autocomplete ( "val" , suggestion . noteTitle ) ;
537- $el . autocomplete ( "close" ) ;
538- $el . trigger ( "autocomplete:noteselected" , [ suggestion ] ) ;
539572 }
540573 }
574+ if ( suggestion . notePath ) {
575+ $el . trigger ( "autocomplete:noteselected" , [ suggestion ] ) ;
576+ }
577+ $el . autocomplete ( "close" ) ;
541578 } ) ;
542579
543580 $el . on ( "autocomplete:closed" , ( ) => {
0 commit comments