@@ -775,6 +775,8 @@ def process_key_event(self, e):
775775 self .on_tab (back = True )
776776 elif e in key_dispatch [self .config .undo_key ]: # ctrl-r for undo
777777 self .prompt_undo ()
778+ elif e in key_dispatch [self .config .redo_key ]: # ctrl-g for redo
779+ self .redo ()
778780 elif e in key_dispatch [self .config .save_key ]: # ctrl-s for save
779781 greenlet .greenlet (self .write2file ).switch ()
780782 elif e in key_dispatch [self .config .pastebin_key ]: # F8 for pastebin
@@ -858,14 +860,17 @@ def readline_kill(self, e):
858860 else :
859861 self .cut_buffer = cut
860862
861- def on_enter (self , insert_into_history = True , reset_rl_history = True ):
863+ def on_enter (self , new_code = True , reset_rl_history = True ):
862864 # so the cursor isn't touching a paren TODO: necessary?
865+ if new_code :
866+ self .redo_stack = []
867+
863868 self ._set_cursor_offset (- 1 , update_completion = False )
864869 if reset_rl_history :
865870 self .rl_history .reset ()
866871
867872 self .history .append (self .current_line )
868- self .push (self .current_line , insert_into_history = insert_into_history )
873+ self .push (self .current_line , insert_into_history = new_code )
869874
870875 def on_tab (self , back = False ):
871876 """Do something on tab key
@@ -1019,7 +1024,7 @@ def send_session_to_external_editor(self, filename=None):
10191024 source = preprocess ("\n " .join (from_editor ), self .interp .compile )
10201025 lines = source .split ("\n " )
10211026 self .history = lines
1022- self .reevaluate (insert_into_history = True )
1027+ self .reevaluate (new_code = True )
10231028 self .current_line = current_line
10241029 self .cursor_offset = len (self .current_line )
10251030 self .status_bar .message (_ ("Session edited and reevaluated" ))
@@ -1030,7 +1035,7 @@ def clear_modules_and_reevaluate(self):
10301035 cursor , line = self .cursor_offset , self .current_line
10311036 for modname in set (sys .modules .keys ()) - self .original_modules :
10321037 del sys .modules [modname ]
1033- self .reevaluate (insert_into_history = True )
1038+ self .reevaluate (new_code = True )
10341039 self .cursor_offset , self .current_line = cursor , line
10351040 self .status_bar .message (
10361041 _ ("Reloaded at %s by user." ) % (time .strftime ("%X" ),)
@@ -1811,7 +1816,15 @@ def prompt_for_undo():
18111816
18121817 greenlet .greenlet (prompt_for_undo ).switch ()
18131818
1814- def reevaluate (self , insert_into_history = False ):
1819+ def redo (self ):
1820+ if (self .redo_stack ):
1821+ temp = self .redo_stack .pop ()
1822+ self .push (temp )
1823+ self .history .append (temp )
1824+ else :
1825+ self .status_bar .message ("Nothing to redo." )
1826+
1827+ def reevaluate (self , new_code = False ):
18151828 """bpython.Repl.undo calls this"""
18161829 if self .watcher :
18171830 self .watcher .reset ()
@@ -1835,7 +1848,7 @@ def reevaluate(self, insert_into_history=False):
18351848 sys .stdin = ReevaluateFakeStdin (self .stdin , self )
18361849 for line in old_logical_lines :
18371850 self ._current_line = line
1838- self .on_enter (insert_into_history = insert_into_history )
1851+ self .on_enter (new_code = new_code )
18391852 while self .fake_refresh_requested :
18401853 self .fake_refresh_requested = False
18411854 self .process_event (bpythonevents .RefreshRequestEvent ())
0 commit comments