From 3e500344282a364f1fbd7245c49d980fe0bfab11 Mon Sep 17 00:00:00 2001 From: Pedro Worcel Date: Sat, 22 Feb 2014 17:15:37 +1300 Subject: fix the wrapping on backward searches --- libmproxy/console/flowview.py | 41 ++++++++++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 15 deletions(-) (limited to 'libmproxy/console') diff --git a/libmproxy/console/flowview.py b/libmproxy/console/flowview.py index 990dc967..8f4cb1eb 100644 --- a/libmproxy/console/flowview.py +++ b/libmproxy/console/flowview.py @@ -365,6 +365,19 @@ class FlowView(common.WWrap): return loop_range + def search_find(self, text, search_string, start_index, backwards): + if backwards == False: + find_index = text.find(search_string, start_index) + else: + if start_index != 0: + start_index -= len(search_string) + else: + start_index = None + + find_index = text.rfind(search_string, 0, start_index) + + return find_index + def search_highlight_text(self, text_objects, search_string, looping = False, backwards = False): start_line, start_index = self.search_get_start(search_string) i = start_line @@ -374,45 +387,43 @@ class FlowView(common.WWrap): loop_range = self.search_get_range(len(text_objects), start_line, backwards) for i in loop_range: text_object = text_objects[i] - if i != start_line: - start_index = 0 try: text, style = text_object.get_text() except AttributeError: raise SearchError() - if backwards == False: - find_index = text.find(search_string, start_index) - else: - if start_index != 0: - start_index -= len(search_string) - else: - start_index = None + if i != start_line: + start_index = 0 - find_index = text.rfind(search_string, 0, start_index) + find_index = self.search_find(text, search_string, start_index, backwards) if find_index != -1: new_text = self.search_highlight_object(text, find_index, search_string) text_objects[i] = new_text + found = True self.state.add_flow_setting(self.flow, "last_search_index", find_index) - self.state.add_flow_setting(self.flow, "last_find_line", i) - found = True break + # handle search WRAP if found: focus_pos = i else : - if (start_line == 0 and start_index == 0) or looping: + if looping: focus_pos = None else: - self.state.add_flow_setting(self.flow, "last_search_index", 0) - self.state.add_flow_setting(self.flow, "last_find_line", 0) + if not backwards: + self.state.add_flow_setting(self.flow, "last_search_index", 0) + self.state.add_flow_setting(self.flow, "last_find_line", 0) + else: + self.state.add_flow_setting(self.flow, "last_search_index", None) + self.state.add_flow_setting(self.flow, "last_find_line", len(text_objects) - 1) + text_objects, focus_pos = self.search_highlight_text(text_objects, search_string, looping=True, backwards=backwards) -- cgit v1.2.3