@@ -524,12 +524,16 @@ def incremental_search(self, reverse=False):
524524 else :
525525 self .special_mode = 'incremental_search'
526526 else :
527- self ._set_current_line (self .rl_history .back (False , search = True )
528- if reverse else
529- self .rl_history .forward (False , search = True ),
530- reset_rl_history = False , clear_special_mode = False )
531- self ._set_cursor_offset (len (self .current_line ), reset_rl_history = False ,
532- clear_special_mode = False )
527+ if self .rl_history .saved_line :
528+ line = (self .rl_history .back (False , search = True )
529+ if reverse else
530+ self .rl_history .forward (False , search = True ))
531+ if self .rl_history .is_at_start :
532+ line = '' # incremental search's search string isn't the current line
533+ self ._set_current_line (line ,
534+ reset_rl_history = False , clear_special_mode = False )
535+ self ._set_cursor_offset (len (self .current_line ),
536+ reset_rl_history = False , clear_special_mode = False )
533537
534538 def readline_kill (self , e ):
535539 func = self .edit_keys [e ]
@@ -695,6 +699,10 @@ def add_normal_character(self, char):
695699 self .cursor_offset = max (0 , self .cursor_offset - 4 )
696700
697701 def add_to_incremental_search (self , char = None , backspace = False ):
702+ """Modify the current search term while in incremental search.
703+
704+ The only operations allowed in incremental search mode are
705+ adding characters and backspacing."""
698706 if char is None and not backspace :
699707 raise ValueError ("must provide a char or set backspace to True" )
700708 saved_line = self .rl_history .saved_line
0 commit comments