@@ -516,6 +516,9 @@ impl Reedline {
516516 #[ must_use]
517517 pub fn with_menu ( mut self , menu : ReedlineMenu ) -> Self {
518518 self . menus . push ( menu) ;
519+ if self . active_menu ( ) . is_none ( ) {
520+ self . activate_menus_on_start ( ) ;
521+ }
519522 self
520523 }
521524
@@ -915,6 +918,7 @@ impl Reedline {
915918 | ReedlineEvent :: HistoryHintWordComplete
916919 | ReedlineEvent :: OpenEditor
917920 | ReedlineEvent :: Menu ( _)
921+ | ReedlineEvent :: MenuAccept
918922 | ReedlineEvent :: MenuNext
919923 | ReedlineEvent :: MenuPrevious
920924 | ReedlineEvent :: MenuUp
@@ -965,6 +969,24 @@ impl Reedline {
965969 }
966970 Ok ( EventStatus :: Inapplicable )
967971 }
972+ ReedlineEvent :: MenuAccept => {
973+ match self . menus . iter_mut ( ) . find ( |menu| menu. is_active ( ) ) {
974+ None => Ok ( EventStatus :: Inapplicable ) ,
975+ Some ( menu) => {
976+ menu. replace_in_buffer ( & mut self . editor ) ;
977+ if !menu. settings ( ) . keep_active_after_accept {
978+ menu. menu_event ( MenuEvent :: Deactivate ) ;
979+ } else {
980+ menu. update_values (
981+ & mut self . editor ,
982+ self . completer . as_mut ( ) ,
983+ self . history . as_ref ( ) ,
984+ ) ;
985+ }
986+ Ok ( EventStatus :: Handled )
987+ }
988+ }
989+ }
968990 ReedlineEvent :: MenuNext => match self . active_menu ( ) {
969991 None => Ok ( EventStatus :: Inapplicable ) ,
970992 Some ( menu) => {
@@ -1083,13 +1105,23 @@ impl Reedline {
10831105 Ok ( EventStatus :: Handled )
10841106 }
10851107 ReedlineEvent :: Enter | ReedlineEvent :: Submit | ReedlineEvent :: SubmitOrNewline
1086- if self . menus . iter ( ) . any ( |menu| menu. is_active ( ) ) =>
1108+ if self
1109+ . menus
1110+ . iter ( )
1111+ . any ( |menu| menu. is_active ( ) && menu. settings ( ) . treat_submit_as_accept ) =>
10871112 {
10881113 for menu in self . menus . iter_mut ( ) {
1089- if menu. is_active ( ) {
1114+ if menu. is_active ( ) && menu . settings ( ) . treat_submit_as_accept {
10901115 menu. replace_in_buffer ( & mut self . editor ) ;
1091- menu. menu_event ( MenuEvent :: Deactivate ) ;
1092-
1116+ if !menu. settings ( ) . keep_active_after_accept {
1117+ menu. menu_event ( MenuEvent :: Deactivate ) ;
1118+ } else {
1119+ menu. update_values (
1120+ & mut self . editor ,
1121+ self . completer . as_mut ( ) ,
1122+ self . history . as_ref ( ) ,
1123+ ) ;
1124+ }
10931125 return Ok ( EventStatus :: Handled ) ;
10941126 }
10951127 }
@@ -1271,6 +1303,13 @@ impl Reedline {
12711303 . for_each ( |menu| menu. menu_event ( MenuEvent :: Deactivate ) ) ;
12721304 }
12731305
1306+ fn activate_menus_on_start ( & mut self ) {
1307+ self . menus
1308+ . iter_mut ( )
1309+ . filter ( |menu| menu. settings ( ) . activate_on_start )
1310+ . for_each ( |menu| menu. menu_event ( MenuEvent :: Activate ( false ) ) ) ;
1311+ }
1312+
12741313 fn previous_history ( & mut self ) {
12751314 if self . history_cursor_on_excluded {
12761315 self . history_cursor_on_excluded = false ;
@@ -1875,6 +1914,7 @@ impl Reedline {
18751914 }
18761915 self . run_edit_commands ( & [ EditCommand :: Clear ] ) ;
18771916 self . editor . reset_undo_stack ( ) ;
1917+ self . activate_menus_on_start ( ) ;
18781918
18791919 Ok ( EventStatus :: Exits ( Signal :: Success ( buffer) ) )
18801920 }
0 commit comments