@@ -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) ;
@@ -504,22 +524,19 @@ mod tests {
504524 . unwrap ( ) ;
505525 assert_eq ! ( ebuf. get_text( ) . trim_end( ) , hidden) ;
506526
507- // Return to parent.
508- ebuf. complete_file (
509- & CompletionStyle :: List ( next) ,
510- & CompletionDisplay :: None ,
511- ctx ! ( gid, vwctx, vctx) ,
512- & mut store,
513- )
514- . unwrap ( ) ;
515- let result = ebuf. get_text ( ) ;
516- let result = Path :: new ( result. trim_end ( ) ) ;
517- assert_eq ! ( result, tmp. path( ) ) ;
527+ // A single completion is directly applied
528+ assert ! ( !ebuf. completions. contains_key( & gid) ) ;
518529
519- // Clear completion list.
520- ebuf. completions . remove ( & gid) ;
530+ // reset to the directory name
531+ let ( mut ebuf, gid, vwctx, mut vctx, mut store) = mkfivestr ( path. as_ref ( ) ) ;
532+ vctx. persist . insert = Some ( InsertStyle :: Insert ) ;
533+ ebuf. set_leader ( gid, Cursor :: new ( 0 , 0 ) ) ;
534+ let mv = mv ! ( MoveType :: LinePos ( MovePosition :: End ) , 0 ) ;
535+ edit ! ( ebuf, EditAction :: Motion , mv, ctx!( gid, vwctx, vctx) , store) ;
521536
522- // Type "h" so we can complete the filename.
537+ // Type "/.h" so we can complete the filename.
538+ type_char ! ( ebuf, MAIN_SEPARATOR , gid, vwctx, vctx, store) ;
539+ type_char ! ( ebuf, '.' , gid, vwctx, vctx, store) ;
523540 type_char ! ( ebuf, 'h' , gid, vwctx, vctx, store) ;
524541
525542 // Complete to ".hidden".
@@ -640,21 +657,11 @@ mod tests {
640657 assert_eq ! ( ebuf1. get_text( ) , "foo bar\n bar\n " ) ;
641658 assert_eq ! ( ebuf1. get_leader( gid) , Cursor :: new( 0 , 7 ) ) ;
642659
643- // Completing again returns to "b".
644- ebuf1
645- . complete_word (
646- & CompletionStyle :: List ( next) ,
647- & CompletionScope :: Buffer ,
648- & CompletionDisplay :: None ,
649- ctx ! ( gid, vwctx, vctx) ,
650- & mut store,
651- )
652- . unwrap ( ) ;
653- assert_eq ! ( ebuf1. get_text( ) , "foo b\n bar\n " ) ;
654- assert_eq ! ( ebuf1. get_leader( gid) , Cursor :: new( 0 , 5 ) ) ;
660+ // A single completion is directly applied
661+ assert ! ( !ebuf1. completions. contains_key( & gid) ) ;
655662
656- // Clear completion list.
657- ebuf1 . completions . remove ( & gid) ;
663+ type_char ! ( ebuf1 , ' ' , gid , vwctx , vctx , store ) ;
664+ type_char ! ( ebuf1 , 'b' , gid, vwctx , vctx , store ) ;
658665
659666 // Completion with Global scope first yields "bar".
660667 ebuf1
@@ -666,8 +673,8 @@ mod tests {
666673 & mut store,
667674 )
668675 . unwrap ( ) ;
669- assert_eq ! ( ebuf1. get_text( ) , "foo bar\n bar\n " ) ;
670- assert_eq ! ( ebuf1. get_leader( gid) , Cursor :: new( 0 , 7 ) ) ;
676+ assert_eq ! ( ebuf1. get_text( ) , "foo bar bar \n bar\n " ) ;
677+ assert_eq ! ( ebuf1. get_leader( gid) , Cursor :: new( 0 , 11 ) ) ;
671678
672679 // Doing it again yields "baz".
673680 ebuf1
@@ -679,8 +686,8 @@ mod tests {
679686 & mut store,
680687 )
681688 . unwrap ( ) ;
682- assert_eq ! ( ebuf1. get_text( ) , "foo baz\n bar\n " ) ;
683- assert_eq ! ( ebuf1. get_leader( gid) , Cursor :: new( 0 , 7 ) ) ;
689+ assert_eq ! ( ebuf1. get_text( ) , "foo bar baz\n bar\n " ) ;
690+ assert_eq ! ( ebuf1. get_leader( gid) , Cursor :: new( 0 , 11 ) ) ;
684691
685692 // And then returns to "b".
686693 ebuf1
@@ -692,8 +699,8 @@ mod tests {
692699 & mut store,
693700 )
694701 . unwrap ( ) ;
695- assert_eq ! ( ebuf1. get_text( ) , "foo b\n bar\n " ) ;
696- assert_eq ! ( ebuf1. get_leader( gid) , Cursor :: new( 0 , 5 ) ) ;
702+ assert_eq ! ( ebuf1. get_text( ) , "foo bar b\n bar\n " ) ;
703+ assert_eq ! ( ebuf1. get_leader( gid) , Cursor :: new( 0 , 9 ) ) ;
697704
698705 // Go backwards to "baz".
699706 ebuf1
@@ -705,7 +712,7 @@ mod tests {
705712 & mut store,
706713 )
707714 . unwrap ( ) ;
708- assert_eq ! ( ebuf1. get_text( ) , "foo baz\n bar\n " ) ;
709- assert_eq ! ( ebuf1. get_leader( gid) , Cursor :: new( 0 , 7 ) ) ;
715+ assert_eq ! ( ebuf1. get_text( ) , "foo bar baz\n bar\n " ) ;
716+ assert_eq ! ( ebuf1. get_leader( gid) , Cursor :: new( 0 , 11 ) ) ;
710717 }
711718}
0 commit comments