@@ -91,28 +91,6 @@ function isTriggerAtCursor(state: EditorState): boolean {
9191 return getTriggerAtCursor ( state ) !== null ;
9292}
9393
94- /** Inserts a suggestion into the editor and dispatches the acceptance effect. */
95- function acceptSuggestion (
96- view : EditorView ,
97- suggestionText : string ,
98- suggestionAcceptanceEffect : StateEffectType < SuggestionAcceptanceState > ,
99- ) {
100- view . dispatch ( {
101- ...insertCompletionText (
102- view . state ,
103- suggestionText ,
104- view . state . selection . main . head ,
105- view . state . selection . main . head ,
106- ) ,
107- } ) ;
108-
109- view . dispatch ( {
110- effects : suggestionAcceptanceEffect . of ( {
111- acceptance : SuggestionAcceptance . ACCEPTED ,
112- } ) ,
113- } ) ;
114- }
115-
11694export enum SuggestionAcceptance {
11795 REJECTED = 0 ,
11896 ACCEPTED = 1 ,
@@ -298,13 +276,28 @@ class InlineSuggestionWidget extends WidgetType {
298276 return span ;
299277 }
300278 accept ( e : MouseEvent , view : EditorView ) {
279+ const suggestionText = this . suggestion ;
301280 const config = view . state . field < SuggestionConfig > ( this . configState ) ;
302281 if ( ! config . acceptOnClick ) return ;
303282
304283 e . stopPropagation ( ) ;
305284 e . preventDefault ( ) ;
306285
307- acceptSuggestion ( view , this . suggestion , this . suggestionAcceptanceEffect ) ;
286+ view . dispatch ( {
287+ ...insertCompletionText (
288+ view . state ,
289+ suggestionText ,
290+ view . state . selection . main . head ,
291+ view . state . selection . main . head ,
292+ ) ,
293+ } ) ;
294+
295+ view . dispatch ( {
296+ effects : this . suggestionAcceptanceEffect . of ( {
297+ acceptance : SuggestionAcceptance . ACCEPTED ,
298+ } ) ,
299+ } ) ;
300+
308301 return true ;
309302 }
310303}
@@ -372,7 +365,14 @@ export function createExtensionKeymapBinding(
372365 return false ;
373366 }
374367
375- acceptSuggestion ( view , suggestionText , suggestionAcceptanceEffect ) ;
368+ view . dispatch ( {
369+ ...insertCompletionText (
370+ view . state ,
371+ suggestionText ,
372+ view . state . selection . main . head ,
373+ view . state . selection . main . head ,
374+ ) ,
375+ } ) ;
376376 logInfo ( "tab handler: suggestion accepted" ) ;
377377 return true ;
378378 } catch ( e ) {
@@ -652,7 +652,20 @@ export function createAutocompleteSuppressor(
652652 e . preventDefault ( ) ;
653653 e . stopImmediatePropagation ( ) ;
654654
655- acceptSuggestion ( this . view , suggestion . suggestion , suggestionAcceptanceEffect ) ;
655+ this . view . dispatch ( {
656+ ...insertCompletionText (
657+ this . view . state ,
658+ suggestion . suggestion ,
659+ this . view . state . selection . main . head ,
660+ this . view . state . selection . main . head ,
661+ ) ,
662+ } ) ;
663+
664+ view . dispatch ( {
665+ effects : suggestionAcceptanceEffect . of ( {
666+ acceptance : SuggestionAcceptance . ACCEPTED ,
667+ } ) ,
668+ } ) ;
656669 } ;
657670
658671 this . view . dom . addEventListener ( "keydown" , this . handleKeydown , true ) ;
0 commit comments