Skip to content

Commit fc7ee66

Browse files
don't include current search string as target for incremental search
1 parent e318b6b commit fc7ee66

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

bpython/curtsiesfrontend/repl.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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

bpython/repl.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ def writetb(self, lines):
139139

140140

141141
class History(object):
142+
"""Stores readline-style history allows access to it"""
142143

143144
def __init__(self, entries=None, duplicates=False):
144145
if entries is None:

0 commit comments

Comments
 (0)