Skip to content

Qt Console history search #627

Closed
wants to merge 1 commit into from
View
28 IPython/frontend/qt/console/history_console_widget.py
@@ -82,7 +82,8 @@ def _up_pressed(self, shift_modifier):
self._history_prefix = input_buffer[:col]
# Perform the search.
- self.history_previous(self._history_prefix)
+ self.history_previous(self._history_prefix,
+ as_prefix=not shift_modifier)
# Go to the first line of the prompt for seemless history scrolling.
# Emulate readline: keep the cursor position fixed for a prefix
@@ -110,7 +111,8 @@ def _down_pressed(self, shift_modifier):
return False
# Perform the search.
- replaced = self.history_next(self._history_prefix)
+ replaced = self.history_next(self._history_prefix,
+ as_prefix=not shift_modifier)
# Emulate readline: keep the cursor position fixed for a prefix
# search. (We don't need to move the cursor to the end of the buffer
@@ -130,13 +132,15 @@ def _down_pressed(self, shift_modifier):
# 'HistoryConsoleWidget' public interface
#---------------------------------------------------------------------------
- def history_previous(self, prefix=''):
+ def history_previous(self, substring='', as_prefix=True):
""" If possible, set the input buffer to a previous history item.
Parameters:
-----------
- prefix : str, optional
- If specified, search for an item with this prefix.
+ substring : str, optional
+ If specified, search for an item with this substring.
+ as_prefix : bool, optional
+ If True, the substring must match at the beginning (default).
Returns:
--------
@@ -147,7 +151,8 @@ def history_previous(self, prefix=''):
while index > 0:
index -= 1
history = self._get_edited_history(index)
- if history.startswith(prefix):
+ if (as_prefix and history.startswith(substring)) \
+ or (not as_prefix and substring in history):
replace = True
break
@@ -158,13 +163,15 @@ def history_previous(self, prefix=''):
return replace
- def history_next(self, prefix=''):
+ def history_next(self, substring='', as_prefix=True):
""" If possible, set the input buffer to a subsequent history item.
Parameters:
-----------
- prefix : str, optional
- If specified, search for an item with this prefix.
+ substring : str, optional
+ If specified, search for an item with this substring.
+ as_prefix : bool, optional
+ If True, the substring must match at the beginning (default).
Returns:
--------
@@ -175,7 +182,8 @@ def history_next(self, prefix=''):
while self._history_index < len(self._history):
index += 1
history = self._get_edited_history(index)
- if history.startswith(prefix):
+ if (as_prefix and history.startswith(substring)) \
+ or (not as_prefix and substring in history):
replace = True
break
Something went wrong with that request. Please try again.