From 80c4de5ca462a211fca33d45fe52441b246d4d03 Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Sun, 29 Mar 2015 15:14:56 +1300 Subject: [PATCH] Keep record of last search term --- libmproxy/console/__init__.py | 3 +-- libmproxy/console/flowview.py | 3 ++- libmproxy/console/searchable.py | 11 ++++++++--- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/libmproxy/console/__init__.py b/libmproxy/console/__init__.py index 9375f973b..d9e49331d 100644 --- a/libmproxy/console/__init__.py +++ b/libmproxy/console/__init__.py @@ -27,10 +27,9 @@ class ConsoleState(flow.State): self.focus = None self.follow_focus = None self.default_body_view = contentview.get("Auto") - self.view_flow_mode = common.VIEW_FLOW_REQUEST - self.flowsettings = weakref.WeakKeyDictionary() + self.last_search = None def __setattr__(self, name, value): self.__dict__[name] = value diff --git a/libmproxy/console/flowview.py b/libmproxy/console/flowview.py index a431d65f8..c38b9fea3 100644 --- a/libmproxy/console/flowview.py +++ b/libmproxy/console/flowview.py @@ -215,7 +215,7 @@ class FlowView(urwid.WidgetWrap): """ headers, msg, body = self.conn_text_raw(conn) merged = self.conn_text_merge(headers, msg, body) - return searchable.Searchable(merged) + return searchable.Searchable(self.state, merged) def _tab(self, content, attr): p = urwid.Text(content) @@ -262,6 +262,7 @@ class FlowView(urwid.WidgetWrap): body = self.conn_text(self.flow.response) else: body = searchable.Searchable( + self.state, [ urwid.Text(""), urwid.Text( diff --git a/libmproxy/console/searchable.py b/libmproxy/console/searchable.py index 5539ecb26..bd1288d5e 100644 --- a/libmproxy/console/searchable.py +++ b/libmproxy/console/searchable.py @@ -14,11 +14,12 @@ class Highlight(urwid.AttrMap): class Searchable(urwid.ListBox): - def __init__(self, contents): + def __init__(self, state, contents): urwid.ListBox.__init__( self, urwid.SimpleFocusListWalker(contents) ) + self.state = state self.search_offset = 0 self.current_highlight = None self.search_term = None @@ -38,6 +39,7 @@ class Searchable(urwid.ListBox): return super(self.__class__, self).keypress(size, key) def set_search(self, text): + self.state.last_search = text self.search_term = text or None self.find_next(False) @@ -61,8 +63,11 @@ class Searchable(urwid.ListBox): def find_next(self, backwards): if not self.search_term: - self.set_highlight(None) - return + if self.state.last_search: + self.search_term = self.state.last_search + else: + self.set_highlight(None) + return # Start search at focus + 1 if backwards: rng = xrange(len(self.body)-1, -1, -1)