From 47117a21aa840e72294312dcb98ea470846e485f Mon Sep 17 00:00:00 2001 From: Rob McMullen Date: Sat, 26 Dec 2015 22:51:05 -0800 Subject: [PATCH] Fixed next/prev searching after cursor move --- omnivore/tasks/hex_edit/commands.py | 31 +++++++++++++++++------------ 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/omnivore/tasks/hex_edit/commands.py b/omnivore/tasks/hex_edit/commands.py index 39d7b635..d9a5ee22 100644 --- a/omnivore/tasks/hex_edit/commands.py +++ b/omnivore/tasks/hex_edit/commands.py @@ -444,18 +444,21 @@ def __init__(self, search_command): Command.__init__(self) self.search_command = search_command - def get_index(self): + def get_index(self, editor): cmd = self.search_command - cmd.current_match_index += 1 - index = cmd.current_match_index - if index >= len(cmd.all_matches): - index = cmd.current_match_index = 0 - return index + cursor_tuple = (editor.cursor_index, 0) + match_index = bisect.bisect_right(cmd.all_matches, cursor_tuple) + if match_index == cmd.current_match_index: + match_index += 1 + if match_index >= len(cmd.all_matches): + match_index = 0 + cmd.current_match_index = match_index + return match_index def perform(self, editor): self.undo_info = undo = UndoInfo() undo.flags.changed_document = False - index = self.get_index() + index = self.get_index(editor) all_matches = self.search_command.all_matches print "FindNext:", all_matches try: @@ -473,10 +476,12 @@ class FindPrevCommand(FindNextCommand): short_name = "findprev" pretty_name = "Find Previous" - def get_index(self): + def get_index(self, editor): cmd = self.search_command - cmd.current_match_index -= 1 - index = cmd.current_match_index - if index < 0: - index = cmd.current_match_index = len(cmd.all_matches) - 1 - return index + cursor_tuple = (editor.cursor_index, 0) + match_index = bisect.bisect_left(cmd.all_matches, cursor_tuple) + match_index -= 1 + if match_index < 0: + match_index = len(cmd.all_matches) - 1 + cmd.current_match_index = match_index + return match_index