Given self.search_str or self.init_search, find next result after current position and reposition the cursor there. Args: rev - True/False search backward if true look_in_cur - True/False start search in current cell
(self, rev=False, look_in_cur=False)
| 384 | self._search_win_open = 0 |
| 385 | |
| 386 | def search_results(self, rev=False, look_in_cur=False): |
| 387 | """Given self.search_str or self.init_search, find next result after |
| 388 | current position and reposition the cursor there. |
| 389 | |
| 390 | Args: rev - True/False search backward if true |
| 391 | look_in_cur - True/False start search in current cell |
| 392 | |
| 393 | """ |
| 394 | if not self.search_str and not self.init_search: |
| 395 | return |
| 396 | self.search_str = self.search_str or self.init_search |
| 397 | yp, xp = self.y + self.win_y, self.x + self.win_x |
| 398 | if rev is True: |
| 399 | data, yp, xp = self._reverse_data(self.data, yp, xp) |
| 400 | else: |
| 401 | data = self.data |
| 402 | if look_in_cur is False: |
| 403 | # Skip ahead/back one cell |
| 404 | if xp < len(data[0]) - 1: |
| 405 | xp += 1 |
| 406 | elif xp >= len(data[0]) - 1 and yp < len(data) - 1: |
| 407 | # Skip ahead a line if at the end of the current line |
| 408 | yp += 1 |
| 409 | xp = 0 |
| 410 | else: |
| 411 | # Skip back to the top if at the end of the data |
| 412 | yp = xp = 0 |
| 413 | search_order = [self._search_cur_line_r, |
| 414 | self._search_next_line_to_end, |
| 415 | self._search_next_line_from_beg, |
| 416 | self._search_cur_line_l] |
| 417 | for search in search_order: |
| 418 | y, x, res = search(data, yp, xp) |
| 419 | if res is True: |
| 420 | yp, xp = y, x |
| 421 | break |
| 422 | if rev is True: |
| 423 | self.data, yp, xp = self._reverse_data(data, yp, xp) |
| 424 | if res is True: |
| 425 | self.goto_yx(yp + 1, xp + 1) |
| 426 | |
| 427 | def search_results_prev(self, rev=False, look_in_cur=False): |
| 428 | """Search backwards""" |
no test coverage detected