aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--libmproxy/console/flowview.py13
-rw-r--r--test/test_console_search.py15
2 files changed, 25 insertions, 3 deletions
diff --git a/libmproxy/console/flowview.py b/libmproxy/console/flowview.py
index 25871b8d..9cdd2923 100644
--- a/libmproxy/console/flowview.py
+++ b/libmproxy/console/flowview.py
@@ -356,13 +356,22 @@ class FlowView(common.WWrap):
return (start_line, start_index)
+ def search_get_range(self, len_text_objects, start_line, backwards):
+ if not backwards:
+ loop_range = range(start_line, len_text_objects)
+ else:
+ loop_range = range(start_line, 0, -1)
+
+ return loop_range
+
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
found = False
text_objects = copy.deepcopy(text_objects)
- for text_object in text_objects[start_line:]:
+ for i in self.search_get_range(len(text_objects), start_line, backwards):
+ text_object = text_objects[i]
if i != start_line:
start_index = None
@@ -391,8 +400,6 @@ class FlowView(common.WWrap):
found = True
break
- i += 1
-
# handle search WRAP
if found:
focus_pos = i
diff --git a/test/test_console_search.py b/test/test_console_search.py
index 7374f399..69c033b9 100644
--- a/test/test_console_search.py
+++ b/test/test_console_search.py
@@ -119,3 +119,18 @@ def test_search_backwards():
text_object = tutils.get_body_line(f.last_displayed_body, 0)
assert text_object.get_text() == first_match
+def test_search_back_multiline():
+ f = tutils.tflowview(request_contents="this is string\nstring is string")
+
+ f.search("string")
+ text_object = tutils.get_body_line(f.last_displayed_body, 0)
+ first_match = ('this is string', [(None, 8), (f.highlight_color, 6)])
+ assert text_object.get_text() == first_match
+
+ f.search_again()
+ text_object = tutils.get_body_line(f.last_displayed_body, 1)
+ assert text_object.get_text() == ('string is string', [(None, 0), (f.highlight_color, 6)])
+
+ f.search_again(backwards=True)
+ text_object = tutils.get_body_line(f.last_displayed_body, 0)
+ assert text_object.get_text() == first_match