@@ -788,9 +788,11 @@ def readline_kill(self, e):
788788 else :
789789 self .cut_buffer = cut
790790
791- def on_enter (self , insert_into_history = True ):
791+ def on_enter (self , insert_into_history = True , reset_rl_history = True ):
792792 # so the cursor isn't touching a paren TODO: necessary?
793793 self ._set_cursor_offset (- 1 , update_completion = False )
794+ if reset_rl_history :
795+ self .rl_history .reset ()
794796
795797 self .history .append (self .current_line )
796798 self .push (self .current_line , insert_into_history = insert_into_history )
@@ -856,14 +858,7 @@ def yank_from_buffer(self):
856858 def operate_and_get_next (self ):
857859 # If we have not navigated back in history
858860 # ctrl+o will have the same effect as enter
859- if self .rl_history .index == 0 or self .rl_history .index == 1 :
860- self .on_enter ()
861- return
862-
863- index = self .rl_history .index
864- self .on_enter ()
865- self .rl_history .index = index
866- self ._set_current_line (self .rl_history .entries [- index ], reset_rl_history = False )
861+ self .on_enter (reset_rl_history = False )
867862
868863 def up_one_line (self ):
869864 self .rl_history .enter (self .current_line )
@@ -1091,7 +1086,11 @@ def run_code_and_maybe_finish(self, for_code=None):
10911086 self .current_stdouterr_line , self .width ))
10921087 self .current_stdouterr_line = ''
10931088
1094- self ._set_current_line (' ' * indent , update_completion = True )
1089+ if self .rl_history .index == 0 :
1090+ self ._set_current_line (' ' * indent , update_completion = True )
1091+ else :
1092+ self ._set_current_line (self .rl_history .entries [- self .rl_history .index ],
1093+ reset_rl_history = False )
10951094 self .cursor_offset = len (self .current_line )
10961095
10971096 def keyboard_interrupt (self ):
0 commit comments