Show More
@@ -82,7 +82,8 b' class HistoryConsoleWidget(ConsoleWidget):' | |||||
82 | self._history_prefix = input_buffer[:col] |
|
82 | self._history_prefix = input_buffer[:col] | |
83 |
|
83 | |||
84 | # Perform the search. |
|
84 | # Perform the search. | |
85 |
self.history_previous(self._history_prefix |
|
85 | self.history_previous(self._history_prefix, | |
|
86 | as_prefix=not shift_modifier) | |||
86 |
|
87 | |||
87 | # Go to the first line of the prompt for seemless history scrolling. |
|
88 | # Go to the first line of the prompt for seemless history scrolling. | |
88 | # Emulate readline: keep the cursor position fixed for a prefix |
|
89 | # Emulate readline: keep the cursor position fixed for a prefix | |
@@ -110,7 +111,8 b' class HistoryConsoleWidget(ConsoleWidget):' | |||||
110 | return False |
|
111 | return False | |
111 |
|
112 | |||
112 | # Perform the search. |
|
113 | # Perform the search. | |
113 |
replaced = self.history_next(self._history_prefix |
|
114 | replaced = self.history_next(self._history_prefix, | |
|
115 | as_prefix=not shift_modifier) | |||
114 |
|
116 | |||
115 | # Emulate readline: keep the cursor position fixed for a prefix |
|
117 | # Emulate readline: keep the cursor position fixed for a prefix | |
116 | # search. (We don't need to move the cursor to the end of the buffer |
|
118 | # search. (We don't need to move the cursor to the end of the buffer | |
@@ -130,13 +132,15 b' class HistoryConsoleWidget(ConsoleWidget):' | |||||
130 | # 'HistoryConsoleWidget' public interface |
|
132 | # 'HistoryConsoleWidget' public interface | |
131 | #--------------------------------------------------------------------------- |
|
133 | #--------------------------------------------------------------------------- | |
132 |
|
134 | |||
133 |
def history_previous(self, |
|
135 | def history_previous(self, substring='', as_prefix=True): | |
134 | """ If possible, set the input buffer to a previous history item. |
|
136 | """ If possible, set the input buffer to a previous history item. | |
135 |
|
137 | |||
136 | Parameters: |
|
138 | Parameters: | |
137 | ----------- |
|
139 | ----------- | |
138 |
|
|
140 | substring : str, optional | |
139 |
If specified, search for an item with this |
|
141 | If specified, search for an item with this substring. | |
|
142 | as_prefix : bool, optional | |||
|
143 | If True, the substring must match at the beginning (default). | |||
140 |
|
144 | |||
141 | Returns: |
|
145 | Returns: | |
142 | -------- |
|
146 | -------- | |
@@ -147,7 +151,8 b' class HistoryConsoleWidget(ConsoleWidget):' | |||||
147 | while index > 0: |
|
151 | while index > 0: | |
148 | index -= 1 |
|
152 | index -= 1 | |
149 | history = self._get_edited_history(index) |
|
153 | history = self._get_edited_history(index) | |
150 |
if history.startswith( |
|
154 | if (as_prefix and history.startswith(substring)) \ | |
|
155 | or (not as_prefix and substring in history): | |||
151 | replace = True |
|
156 | replace = True | |
152 | break |
|
157 | break | |
153 |
|
158 | |||
@@ -158,13 +163,15 b' class HistoryConsoleWidget(ConsoleWidget):' | |||||
158 |
|
163 | |||
159 | return replace |
|
164 | return replace | |
160 |
|
165 | |||
161 |
def history_next(self, |
|
166 | def history_next(self, substring='', as_prefix=True): | |
162 | """ If possible, set the input buffer to a subsequent history item. |
|
167 | """ If possible, set the input buffer to a subsequent history item. | |
163 |
|
168 | |||
164 | Parameters: |
|
169 | Parameters: | |
165 | ----------- |
|
170 | ----------- | |
166 |
|
|
171 | substring : str, optional | |
167 |
If specified, search for an item with this |
|
172 | If specified, search for an item with this substring. | |
|
173 | as_prefix : bool, optional | |||
|
174 | If True, the substring must match at the beginning (default). | |||
168 |
|
175 | |||
169 | Returns: |
|
176 | Returns: | |
170 | -------- |
|
177 | -------- | |
@@ -175,7 +182,8 b' class HistoryConsoleWidget(ConsoleWidget):' | |||||
175 | while self._history_index < len(self._history): |
|
182 | while self._history_index < len(self._history): | |
176 | index += 1 |
|
183 | index += 1 | |
177 | history = self._get_edited_history(index) |
|
184 | history = self._get_edited_history(index) | |
178 |
if history.startswith( |
|
185 | if (as_prefix and history.startswith(substring)) \ | |
|
186 | or (not as_prefix and substring in history): | |||
179 | replace = True |
|
187 | replace = True | |
180 | break |
|
188 | break | |
181 |
|
189 |
General Comments 0
You need to be logged in to leave comments.
Login now