Keep record of last search term

This commit is contained in:
Aldo Cortesi 2015-03-29 15:14:56 +13:00
parent bf012e0a89
commit 80c4de5ca4
3 changed files with 11 additions and 6 deletions

View File

@ -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

View File

@ -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(

View File

@ -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)