@@ -105,6 +105,11 @@ where
105105 let adjs = list. replace ( & mut self . text , val) ;
106106 list. cursor . adjust ( & adjs) ;
107107 self . _adjust_all ( adjs, store) ;
108+
109+ // apply single completion instantly
110+ if list. candidates . len ( ) == 1 {
111+ return Ok ( None ) ;
112+ }
108113 }
109114
110115 self . completions . insert ( gid, list) ;
@@ -158,6 +163,11 @@ where
158163 let adjs = list. replace ( & mut self . text , val) ;
159164 list. cursor . adjust ( & adjs) ;
160165 self . _adjust_all ( adjs, store) ;
166+
167+ // apply single completion instantly
168+ if list. candidates . len ( ) == 1 {
169+ return Ok ( None ) ;
170+ }
161171 }
162172
163173 self . completions . insert ( gid, list) ;
@@ -219,6 +229,11 @@ where
219229 let adjs = list. replace ( & mut self . text , val) ;
220230 list. cursor . adjust ( & adjs) ;
221231 self . _adjust_all ( adjs, store) ;
232+
233+ // apply single completion instantly
234+ if list. candidates . len ( ) == 1 {
235+ return Ok ( None ) ;
236+ }
222237 }
223238
224239 self . completions . insert ( gid, list) ;
@@ -280,6 +295,11 @@ where
280295 let adjs = list. replace ( & mut self . text , val) ;
281296 list. cursor . adjust ( & adjs) ;
282297 self . _adjust_all ( adjs, store) ;
298+
299+ // apply single completion instantly
300+ if list. candidates . len ( ) == 1 {
301+ return Ok ( None ) ;
302+ }
283303 }
284304
285305 self . completions . insert ( gid, list) ;
@@ -664,21 +684,11 @@ mod tests {
664684 assert_eq ! ( ebuf1. get_text( ) , "foo bar\n bar\n " ) ;
665685 assert_eq ! ( ebuf1. get_leader( gid) , Cursor :: new( 0 , 7 ) ) ;
666686
667- // Completing again returns to "b".
668- ebuf1
669- . complete_word (
670- & CompletionStyle :: List ( next) ,
671- & CompletionScope :: Buffer ,
672- & CompletionDisplay :: None ,
673- ctx ! ( gid, vwctx, vctx) ,
674- & mut store,
675- )
676- . unwrap ( ) ;
677- assert_eq ! ( ebuf1. get_text( ) , "foo b\n bar\n " ) ;
678- assert_eq ! ( ebuf1. get_leader( gid) , Cursor :: new( 0 , 5 ) ) ;
687+ // A single completion is directly applied
688+ assert ! ( !ebuf1. completions. contains_key( & gid) ) ;
679689
680- // Clear completion list.
681- ebuf1 . completions . remove ( & gid) ;
690+ type_char ! ( ebuf1 , ' ' , gid , vwctx , vctx , store ) ;
691+ type_char ! ( ebuf1 , 'b' , gid, vwctx , vctx , store ) ;
682692
683693 // Completion with Global scope first yields "bar".
684694 ebuf1
@@ -690,8 +700,8 @@ mod tests {
690700 & mut store,
691701 )
692702 . unwrap ( ) ;
693- assert_eq ! ( ebuf1. get_text( ) , "foo bar\n bar\n " ) ;
694- assert_eq ! ( ebuf1. get_leader( gid) , Cursor :: new( 0 , 7 ) ) ;
703+ assert_eq ! ( ebuf1. get_text( ) , "foo bar bar \n bar\n " ) ;
704+ assert_eq ! ( ebuf1. get_leader( gid) , Cursor :: new( 0 , 11 ) ) ;
695705
696706 // Doing it again yields "baz".
697707 ebuf1
@@ -703,8 +713,8 @@ mod tests {
703713 & mut store,
704714 )
705715 . unwrap ( ) ;
706- assert_eq ! ( ebuf1. get_text( ) , "foo baz\n bar\n " ) ;
707- assert_eq ! ( ebuf1. get_leader( gid) , Cursor :: new( 0 , 7 ) ) ;
716+ assert_eq ! ( ebuf1. get_text( ) , "foo bar baz\n bar\n " ) ;
717+ assert_eq ! ( ebuf1. get_leader( gid) , Cursor :: new( 0 , 11 ) ) ;
708718
709719 // And then returns to "b".
710720 ebuf1
@@ -716,8 +726,8 @@ mod tests {
716726 & mut store,
717727 )
718728 . unwrap ( ) ;
719- assert_eq ! ( ebuf1. get_text( ) , "foo b\n bar\n " ) ;
720- assert_eq ! ( ebuf1. get_leader( gid) , Cursor :: new( 0 , 5 ) ) ;
729+ assert_eq ! ( ebuf1. get_text( ) , "foo bar b\n bar\n " ) ;
730+ assert_eq ! ( ebuf1. get_leader( gid) , Cursor :: new( 0 , 9 ) ) ;
721731
722732 // Go backwards to "baz".
723733 ebuf1
@@ -729,7 +739,7 @@ mod tests {
729739 & mut store,
730740 )
731741 . unwrap ( ) ;
732- assert_eq ! ( ebuf1. get_text( ) , "foo baz\n bar\n " ) ;
733- assert_eq ! ( ebuf1. get_leader( gid) , Cursor :: new( 0 , 7 ) ) ;
742+ assert_eq ! ( ebuf1. get_text( ) , "foo bar baz\n bar\n " ) ;
743+ assert_eq ! ( ebuf1. get_leader( gid) , Cursor :: new( 0 , 11 ) ) ;
734744 }
735745}
0 commit comments