Search history for the current line contents up to the cursor. Selects the first item found. If nothing is under the cursor, any next item in history is selected.
(self, *, forwards: bool)
| 325 | return super().get_prompt(lineno, cursor_on_line) |
| 326 | |
| 327 | def search_next(self, *, forwards: bool) -> None: |
| 328 | """Search history for the current line contents up to the cursor. |
| 329 | |
| 330 | Selects the first item found. If nothing is under the cursor, any next |
| 331 | item in history is selected. |
| 332 | """ |
| 333 | pos = self.pos |
| 334 | s = self.get_unicode() |
| 335 | history_index = self.historyi |
| 336 | |
| 337 | # In multiline contexts, we're only interested in the current line. |
| 338 | nl_index = s.rfind('\n', 0, pos) |
| 339 | prefix = s[nl_index + 1:pos] |
| 340 | pos = len(prefix) |
| 341 | |
| 342 | match_prefix = len(prefix) |
| 343 | len_item = 0 |
| 344 | if history_index < len(self.history): |
| 345 | len_item = len(self.get_item(history_index)) |
| 346 | if len_item and pos == len_item: |
| 347 | match_prefix = False |
| 348 | elif not pos: |
| 349 | match_prefix = False |
| 350 | |
| 351 | while 1: |
| 352 | if forwards: |
| 353 | out_of_bounds = history_index >= len(self.history) - 1 |
| 354 | else: |
| 355 | out_of_bounds = history_index == 0 |
| 356 | if out_of_bounds: |
| 357 | if forwards and not match_prefix: |
| 358 | self.pos = 0 |
| 359 | self.buffer = [] |
| 360 | self.dirty = True |
| 361 | else: |
| 362 | self.error("not found") |
| 363 | return |
| 364 | |
| 365 | history_index += 1 if forwards else -1 |
| 366 | s = self.get_item(history_index) |
| 367 | |
| 368 | if not match_prefix: |
| 369 | self.select_item(history_index) |
| 370 | return |
| 371 | |
| 372 | len_acc = 0 |
| 373 | for i, line in enumerate(s.splitlines(keepends=True)): |
| 374 | if line.startswith(prefix): |
| 375 | self.select_item(history_index) |
| 376 | self.pos = pos + len_acc |
| 377 | return |
| 378 | len_acc += len(line) |
| 379 | |
| 380 | def isearch_next(self) -> None: |
| 381 | st = self.isearch_term |
no test coverage detected