@@ -38,7 +38,7 @@ export const buildResourceSuggestion = (
3838 drive : string ,
3939) : Partial < SuggestionOptions > => ( {
4040 items : async ( { query } : { query : string } ) : Promise < SuggestionItem [ ] > => {
41- const results = await store . search ( query , {
41+ const results = await store . search ( query . toLowerCase ( ) , {
4242 limit : 10 ,
4343 // Including the results could lead to weird behavior when the document itself is returned from the server.
4444 include : false ,
@@ -53,11 +53,7 @@ export const buildResourceSuggestion = (
5353 icon : getIconForClass ( r . getClasses ( ) [ 0 ] ) ,
5454 command : ( { editor, range } ) => {
5555 const subject = r . subject ;
56- const textBeforeQuery = getTextBeforeQuery ( editor , range ) ;
57-
58- // If there is text before the query we are in not in a block context and the resource should be inserted inline.
59- const isBlockContext = textBeforeQuery . length === 0 ;
60-
56+ const isBlockContext = getIsBlockContext ( editor , range ) ;
6157 const command = editor . chain ( ) . focus ( ) . deleteRange ( range ) ;
6258
6359 if ( isBlockContext ) {
@@ -72,17 +68,12 @@ export const buildResourceSuggestion = (
7268 render : createRenderFunction < SuggestionItem > ( container ) ,
7369} ) ;
7470
75- const getTextBeforeQuery = ( editor : Editor , range : Range ) => {
71+ const getIsBlockContext = ( editor : Editor , range : Range ) => {
7672 const { from } = range ;
7773
78- const queryText = editor . state . doc . textBetween ( range . from , range . to ) ;
79-
8074 // Resolve the position and the parent node
8175 const $pos = editor . state . doc . resolve ( from ) ;
82- const parentNode = $pos . parent ;
83-
84- // Calculate the offset within the parent node where the query starts
85- const startOfQueryOffset = $pos . parentOffset - queryText . length ;
8676
87- return parentNode . textContent . substring ( 0 , startOfQueryOffset ) . trim ( ) ;
77+ // Text offset tells us the distance to a previous node. This is 0 if there is no previous node meaning we are in a block context.
78+ return $pos . textOffset === 0 ;
8879} ;
0 commit comments