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