File tree Expand file tree Collapse file tree 1 file changed +22
-12
lines changed Expand file tree Collapse file tree 1 file changed +22
-12
lines changed Original file line number Diff line number Diff line change @@ -293,18 +293,28 @@ export class SuggestionMenuProseMirrorPlugin<
293293 } ,
294294
295295 props : {
296- handleTextInput ( view , _from , _to , text ) {
297- if ( triggerCharacters . includes ( text ) ) {
298- view . dispatch ( view . state . tr . insertText ( text ) ) ;
299- view . dispatch (
300- view . state . tr
301- . setMeta ( suggestionMenuPluginKey , {
302- triggerCharacter : text ,
303- } )
304- . scrollIntoView ( ) ,
305- ) ;
306-
307- return true ;
296+ handleTextInput ( view , from , to , text ) {
297+ // only on insert
298+ if ( from === to ) {
299+ const doc = view . state . doc ;
300+ for ( const str of triggerCharacters ) {
301+ const snippet =
302+ str . length > 1
303+ ? doc . textBetween ( from - str . length , from ) + text
304+ : text ;
305+
306+ if ( str === snippet ) {
307+ view . dispatch ( view . state . tr . insertText ( text ) ) ;
308+ view . dispatch (
309+ view . state . tr
310+ . setMeta ( suggestionMenuPluginKey , {
311+ triggerCharacter : snippet ,
312+ } )
313+ . scrollIntoView ( ) ,
314+ ) ;
315+ return true ;
316+ }
317+ }
308318 }
309319 return false ;
310320 } ,
You can’t perform that action at this time.
0 commit comments