@@ -254,7 +254,12 @@ export class CTCodeEditor extends BaseElement {
254254 type : "text" ,
255255 info : "Create new backlink" ,
256256 apply : ( ) => {
257- this . emit ( "backlink-create" , { text : raw } ) ;
257+ // Instantiate the pattern if available
258+ if ( this . pattern ) {
259+ this . createBacklinkFromPattern ( raw ) ;
260+ } else {
261+ this . emit ( "backlink-create" , { text : raw } ) ;
262+ }
258263 } ,
259264 } ) ;
260265 }
@@ -436,9 +441,11 @@ export class CTCodeEditor extends BaseElement {
436441 if ( charm ) {
437442 // this is VERY specific
438443 // if you do `getEntityId(mentionableArray.key(i))` you'll get a different answer (the ID of the array itself)
439- const charmIdObj = getEntityId ( mentionableArray . get ( ) [ i ] ) ;
440- const charmId = charmIdObj ?. [ "/" ] || "" ;
441- if ( charmId === id ) {
444+ const charmIdObjA = getEntityId ( mentionableArray . get ( ) [ i ] ) ;
445+ const charmIdObjB = getEntityId ( mentionableArray . key ( i ) ) ;
446+ const charmIdA = charmIdObjA ?. [ "/" ] || "" ;
447+ const charmIdB = charmIdObjB ?. [ "/" ] || "" ;
448+ if ( charmIdA === id || charmIdB === id ) {
442449 return charm ;
443450 }
444451 }
@@ -797,14 +804,19 @@ export class CTCodeEditor extends BaseElement {
797804 // Try accepting an active completion first
798805 if ( acceptCompletion ( view ) ) return true ;
799806
800- // If typing a backlink with no matches, emit create event
807+ // If typing a backlink with no matches, create new backlink
801808 const query = this . _currentBacklinkQuery ( view ) ;
802809 if ( query != null ) {
803810 const matches = this . getFilteredMentionable ( query ) ;
804811 if ( matches . length === 0 ) {
805812 const text = query . trim ( ) ;
806813 if ( text . length > 0 ) {
807- this . emit ( "backlink-create" , { text } ) ;
814+ // Instantiate the pattern if available
815+ if ( this . pattern ) {
816+ this . createBacklinkFromPattern ( text ) ;
817+ } else {
818+ this . emit ( "backlink-create" , { text } ) ;
819+ }
808820 return true ;
809821 }
810822 }
0 commit comments