@@ -111,9 +111,6 @@ function! copilot#Clear() abort
111111 if exists (' g:_copilot_timer' )
112112 call timer_stop (remove (g: , ' _copilot_timer' ))
113113 endif
114- if exists (' s:uuid' )
115- call copilot#Request (' notifyRejected' , {' uuids' : [remove (s: , ' uuid' )]})
116- endif
117114 if exists (' b:_copilot' )
118115 call copilot#agent#Cancel (get (b: _copilot , ' first' , {}))
119116 call copilot#agent#Cancel (get (b: _copilot , ' cycling' , {}))
@@ -123,7 +120,14 @@ function! copilot#Clear() abort
123120 return ' '
124121endfunction
125122
123+ function ! s: Reject () abort
124+ if exists (' s:uuid' )
125+ call copilot#Request (' notifyRejected' , {' uuids' : [remove (s: , ' uuid' )]})
126+ endif
127+ endfunction
128+
126129function ! copilot#Dismiss () abort
130+ call s: Reject ()
127131 call copilot#Clear ()
128132 call s: UpdatePreview ()
129133 return ' '
@@ -388,6 +392,7 @@ function! s:UpdatePreview() abort
388392 endif
389393 endif
390394 if uuid !=# get (s: , ' uuid' , ' ' )
395+ call s: Reject ()
391396 let s: uuid = uuid
392397 call copilot#Request (' notifyShown' , {' uuid' : uuid})
393398 endif
@@ -466,6 +471,10 @@ function! copilot#OnCursorMovedI() abort
466471 return copilot#Schedule ()
467472endfunction
468473
474+ function ! copilot#OnVimLeavePre () abort
475+ return s: Reject ()
476+ endfunction
477+
469478function ! copilot#TextQueuedForInsertion () abort
470479 try
471480 return remove (s: , ' suggestion_text' )
0 commit comments