@@ -949,19 +949,46 @@ private void MenuCompleteImpl(Menu menu, CommandCompletion completions)
949949 else if ( nextKey == Keys . Tab )
950950 {
951951 // Search for possible unambiguous common prefix.
952- string unAmbiguousText = GetUnambiguousPrefix ( menu . MenuItems , out ambiguous ) ;
953- int userComplPos = unAmbiguousText . IndexOf ( userCompletionText , StringComparison . OrdinalIgnoreCase ) ;
952+ string unambiguousText = GetUnambiguousPrefix ( menu . MenuItems , out ambiguous ) ;
953+ int userComplPos = unambiguousText . IndexOf ( userCompletionText , StringComparison . OrdinalIgnoreCase ) ;
954954
955955 // ... If found - advance IncrementalCompletion ...
956- if ( unAmbiguousText . Length > 0 && userComplPos >= 0 &&
957- unAmbiguousText . Length > ( userComplPos + userCompletionText . Length ) )
956+ if ( unambiguousText . Length > 0 && userComplPos >= 0 &&
957+ unambiguousText . Length > ( userComplPos + userCompletionText . Length ) )
958958 {
959- userCompletionText = unAmbiguousText . Substring ( userComplPos ) ;
960- _current = completions . ReplacementIndex +
961- FindUserCompletionTextPosition ( menu . MenuItems [ menu . CurrentSelection ] , userCompletionText ) +
962- userCompletionText . Length ;
963- Render ( ) ;
964- Ding ( ) ;
959+ // Obtain all the menu items beginning with unambigousText, so we can count them.
960+ var unambiguousMenuItems = menu . MenuItems . Where ( item => item . CompletionText . StartsWith ( unambiguousText ) ) ;
961+ // If there is only 1 item, and it is a container, then complete it and append the directory separator.
962+ if ( Enumerable . Count ( unambiguousMenuItems ) == 1 )
963+ {
964+ processingKeys = false ;
965+ int cursorAdjustment = 0 ;
966+ var onlyResult = unambiguousMenuItems . First ( ) ;
967+ _current = onlyResult . CompletionText . Length ;
968+
969+ if ( onlyResult . ResultType == CompletionResultType . ProviderContainer )
970+ {
971+ userCompletionText = GetUnquotedText (
972+ GetReplacementTextForDirectory ( onlyResult . CompletionText , ref cursorAdjustment ) ,
973+ consistentQuoting : false ) ;
974+ }
975+ else
976+ {
977+ userCompletionText = GetUnquotedText ( onlyResult , consistentQuoting : false ) ;
978+ }
979+ _current -= cursorAdjustment ;
980+ // If Tabbing into a container (directory), then repeat tab for a menu on its contents (faster navigation).
981+ PrependQueuedKeys ( nextKey ) ;
982+ }
983+ else
984+ {
985+ userCompletionText = unambiguousText . Substring ( userComplPos ) ;
986+ _current = completions . ReplacementIndex +
987+ FindUserCompletionTextPosition ( menu . MenuItems [ menu . CurrentSelection ] , userCompletionText ) +
988+ userCompletionText . Length ;
989+ Render ( ) ;
990+ Ding ( ) ;
991+ }
965992 }
966993 // ... if no - usual Tab behaviour
967994 else
0 commit comments