@@ -419,7 +419,7 @@ endfunction
419419
420420function ! copilot#IsMapped () abort
421421 return get (g: , ' copilot_assume_mapped' ) ||
422- \ hasmapto (' copilot#Accept (' , ' i' )
422+ \ hasmapto (' copilot#AcceptOne (' , ' i' )
423423endfunction
424424let s: is_mapped = copilot#IsMapped ()
425425
@@ -465,7 +465,57 @@ function! copilot#TextQueuedForInsertion() abort
465465 endtry
466466endfunction
467467
468- function ! copilot#Accept (... ) abort
468+ let s: sugg_buffer = {' sugg' : ' ' , ' count' : 0 , ' text' : ' ' , ' valid' : v: false }
469+ function ! copilot#AcceptOne (... ) abort
470+
471+ if ! s: sugg_buffer .valid
472+ let s = copilot#GetDisplayedSuggestion ()
473+ if ! empty (s )
474+ " split the suggestion into words, keep the trailing space
475+ let s: sugg_buffer = {' sugg' : s , ' count' : 0 , ' text' : split (s .text, ' [\t ]\zs' ) , ' valid' : v: true }
476+ " if the text is whitespace, invalidate the buffer
477+ if (len (s: sugg_buffer .text)== 0 ) || ! (s: sugg_buffer .text[0 ] = ~# ' \S' )
478+ let s: sugg_buffer .valid = v: false
479+ endif
480+ endif
481+ endif
482+
483+ if s: sugg_buffer .valid
484+ let s: suggestion_text = s: sugg_buffer .text[s: sugg_buffer .count ]
485+ let s: sugg_buffer .count += 1
486+ if s: sugg_buffer .count >= len (s: sugg_buffer .text)
487+ let s: sugg_buffer .valid = v: false
488+ unlet ! b: _copilot
489+ call copilot#Request (' notifyAccepted' , {' uuid' : s: sugg_buffer .sugg.uuid})
490+ unlet ! s: uuid
491+ call s: ClearPreview ()
492+ endif
493+ if s: sugg_buffer .valid && s: sugg_buffer .count == 1
494+ return repeat (" \<Left>\<Del> " , s: sugg_buffer .sugg.outdentSize) . repeat (" \<Del> " , s: sugg_buffer .sugg.deleteSize) .
495+ \ " \<C-R>\<C-O> =copilot#TextQueuedForInsertion()\<CR> "
496+ endif
497+ return " \<C-R>\<C-O> =copilot#TextQueuedForInsertion()\<CR> "
498+ endif
499+
500+ let default = get (g: , ' copilot_tab_fallback' , pumvisible () ? " \<C-N> " : " \t " )
501+ if ! a: 0
502+ return default
503+ elseif type (a: 1 ) == v: t_string
504+ return a: 1
505+ elseif type (a: 1 ) == v: t_func
506+ try
507+ return call (a: 1 , [])
508+ catch
509+ call copilot#logger#Exception ()
510+ return default
511+ endtry
512+ else
513+ return default
514+ endif
515+ endfunction
516+
517+
518+ function ! copilot#AcceptAll (... ) abort
469519 let s = copilot#GetDisplayedSuggestion ()
470520 if ! empty (s .text)
471521 unlet ! b: _copilot
0 commit comments