aboutsummaryrefslogtreecommitdiffstats
path: root/libmproxy/console
diff options
context:
space:
mode:
authorPedro Worcel <pedro@worcel.com>2014-02-22 17:15:37 +1300
committerPedro Worcel <pedro@worcel.com>2014-02-22 17:15:37 +1300
commit3e500344282a364f1fbd7245c49d980fe0bfab11 (patch)
treea6c0acad04addf8509c0d1efd9b7aa3fd8edb688 /libmproxy/console
parent9fe6b8fd268c95fc1a93148c6e2f4cd4d8a5bb05 (diff)
downloadmitmproxy-3e500344282a364f1fbd7245c49d980fe0bfab11.tar.gz
mitmproxy-3e500344282a364f1fbd7245c49d980fe0bfab11.tar.bz2
mitmproxy-3e500344282a364f1fbd7245c49d980fe0bfab11.zip
fix the wrapping on backward searches
Diffstat (limited to 'libmproxy/console')
-rw-r--r--libmproxy/console/flowview.py41
1 files changed, 26 insertions, 15 deletions
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)