@@ -307,6 +307,7 @@ def smarter_request_reload(desc):
307
307
self .list_win_visible = False # whether the infobox (suggestions, docstring) is visible
308
308
self .watching_files = False # auto reloading turned on
309
309
self .special_mode = None # 'reverse_incremental_search' and 'incremental_search'
310
+ self .incremental_search_target = ''
310
311
311
312
self .original_modules = sys .modules .keys ()
312
313
@@ -510,30 +511,33 @@ def process_key_event(self, e):
510
511
elif e in key_dispatch [self .config .edit_current_block_key ]:
511
512
self .send_current_block_to_external_editor ()
512
513
elif e in ["<ESC>" ]: #ESC
513
- pass
514
+ self . special_mode = None
514
515
elif e in ["<SPACE>" ]:
515
516
self .add_normal_character (' ' )
516
517
else :
517
518
self .add_normal_character (e )
518
519
519
- def incremental_search (self , reverse = False ):
520
+ def incremental_search (self , reverse = False , include_current = False ):
520
521
if self .special_mode == None :
521
- current_line = ''
522
- if reverse :
523
- self .special_mode = 'reverse_incremental_search'
524
- else :
525
- self .special_mode = 'incremental_search'
522
+ self .rl_history .enter (self .current_line )
523
+ self .incremental_search_target = ''
526
524
else :
527
- if self .rl_history .saved_line :
528
- line = (self .rl_history .back (False , search = True )
525
+ if self .incremental_search_target :
526
+ line = (self .rl_history .back (False , search = True ,
527
+ target = self .incremental_search_target ,
528
+ include_current = include_current )
529
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
530
+ self .rl_history .forward (False , search = True ,
531
+ target = self .incremental_search_target ,
532
+ include_current = include_current ))
533
533
self ._set_current_line (line ,
534
534
reset_rl_history = False , clear_special_mode = False )
535
535
self ._set_cursor_offset (len (self .current_line ),
536
536
reset_rl_history = False , clear_special_mode = False )
537
+ if reverse :
538
+ self .special_mode = 'reverse_incremental_search'
539
+ else :
540
+ self .special_mode = 'incremental_search'
537
541
538
542
def readline_kill (self , e ):
539
543
func = self .edit_keys [e ]
@@ -687,7 +691,7 @@ def toggle_file_watch(self):
687
691
def add_normal_character (self , char ):
688
692
if len (char ) > 1 or is_nop (char ):
689
693
return
690
- if self .special_mode == 'reverse_incremental_search' :
694
+ if self .special_mode :
691
695
self .add_to_incremental_search (char )
692
696
else :
693
697
self .current_line = (self .current_line [:self .cursor_offset ] +
@@ -705,18 +709,14 @@ def add_to_incremental_search(self, char=None, backspace=False):
705
709
adding characters and backspacing."""
706
710
if char is None and not backspace :
707
711
raise ValueError ("must provide a char or set backspace to True" )
708
- saved_line = self .rl_history .saved_line
709
712
if backspace :
710
- saved_line = saved_line [:- 1 ]
713
+ self . incremental_search_target = self . incremental_search_target [:- 1 ]
711
714
else :
712
- saved_line += char
713
- self .update_completion ()
714
- self .rl_history .reset ()
715
- self .rl_history .enter (saved_line )
715
+ self .incremental_search_target += char
716
716
if self .special_mode == 'reverse_incremental_search' :
717
- self .incremental_search (reverse = True )
717
+ self .incremental_search (reverse = True , include_current = True )
718
718
elif self .special_mode == 'incremental_search' :
719
- self .incremental_search ()
719
+ self .incremental_search (include_current = True )
720
720
else :
721
721
raise ValueError ('add_to_incremental_search should only be called in a special mode' )
722
722
@@ -888,7 +888,10 @@ def current_line_formatted(self):
888
888
"""The colored current line (no prompt, not wrapped)"""
889
889
if self .config .syntax :
890
890
fs = bpythonparse (format (self .tokenize (self .current_line ), self .formatter ))
891
- if self .rl_history .saved_line in self .current_line :
891
+ if self .special_mode :
892
+ if self .incremental_search_target in self .current_line :
893
+ fs = fmtfuncs .on_magenta (self .incremental_search_target ).join (fs .split (self .incremental_search_target ))
894
+ elif self .rl_history .saved_line and self .rl_history .saved_line in self .current_line :
892
895
if self .config .curtsies_right_arrow_completion :
893
896
fs = fmtfuncs .on_magenta (self .rl_history .saved_line ).join (fs .split (self .rl_history .saved_line ))
894
897
logger .debug ('Display line %r -> %r' , self .current_line , fs )
@@ -921,7 +924,10 @@ def display_line_with_prompt(self):
921
924
"""colored line with prompt"""
922
925
if self .special_mode == 'reverse_incremental_search' :
923
926
return func_for_letter (self .config .color_scheme ['prompt' ])(
924
- '(reverse-i-search)`%s\' : ' % (self .rl_history .saved_line ,)) + self .current_line_formatted
927
+ '(reverse-i-search)`%s\' : ' % (self .incremental_search_target ,)) + self .current_line_formatted
928
+ elif self .special_mode == 'incremental_search' :
929
+ return func_for_letter (self .config .color_scheme ['prompt' ])(
930
+ '(i-search)`%s\' : ' % (self .incremental_search_target ,)) + self .current_line_formatted
925
931
return (func_for_letter (self .config .color_scheme ['prompt' ])(self .ps1 )
926
932
if self .done else
927
933
func_for_letter (self .config .color_scheme ['prompt_more' ])(self .ps2 )) + self .current_line_formatted
0 commit comments