mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-23 08:11:00 +00:00
Keep record of last search term
This commit is contained in:
parent
bf012e0a89
commit
80c4de5ca4
@ -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
|
||||
|
@ -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(
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user