From 166237254dc6c5c6b4ea183f9d107c6e8026745a Mon Sep 17 00:00:00 2001 From: Michael J Gruber Date: Sat, 17 Oct 2020 17:37:56 +0200 Subject: [PATCH] taglist: refine search from buffer When a taglist buffer lists tags from a search or thead buffer (with `--msgs`) then selecting a tag lists all messages in the db with that tag. This feels counter-intuitive. Instead, remember the original query and refine the query by filtering on the tag in addition to the original query. --- alot/buffers/taglist.py | 3 ++- alot/commands/globals.py | 6 +++++- alot/commands/taglist.py | 9 +++++++-- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/alot/buffers/taglist.py b/alot/buffers/taglist.py index f926a77cf..e3342eca8 100644 --- a/alot/buffers/taglist.py +++ b/alot/buffers/taglist.py @@ -13,10 +13,11 @@ class TagListBuffer(Buffer): modename = 'taglist' - def __init__(self, ui, alltags=None, filtfun=lambda x: True): + def __init__(self, ui, alltags=None, filtfun=lambda x: True, querystring=None): self.filtfun = filtfun self.ui = ui self.tags = alltags or [] + self.querystring = querystring self.isinitialized = False self.rebuild() Buffer.__init__(self, ui, self.body) diff --git a/alot/commands/globals.py b/alot/commands/globals.py index 7058fd53e..777c00593 100644 --- a/alot/commands/globals.py +++ b/alot/commands/globals.py @@ -579,13 +579,16 @@ def __init__(self, filtfun=lambda x: True, tags=None, match=None, msgs=False, ** Command.__init__(self, **kwargs) def apply(self, ui): + querystring = None if self.tags: tags = self.tags elif self.msgs and isinstance(ui.current_buffer, buffers.SearchBuffer): tags = list(ui.dbman.query(ui.current_buffer.querystring). search_messages().collect_tags()) + querystring = ui.current_buffer.querystring elif self.msgs and isinstance(ui.current_buffer, buffers.ThreadBuffer): tags = list(ui.current_buffer.thread.get_tags()) + querystring = 'thread:%s' % ui.current_buffer.thread.get_thread_id() else: tags = ui.dbman.get_all_tags() blists = ui.get_buffers_of_type(buffers.TagListBuffer) @@ -593,10 +596,11 @@ def apply(self, ui): buf = blists[0] buf.filtfun = self.filtfun buf.tags = tags + buf.querystring = querystring buf.rebuild() ui.buffer_focus(buf) else: - ui.buffer_open(buffers.TagListBuffer(ui, tags, self.filtfun)) + ui.buffer_open(buffers.TagListBuffer(ui, tags, self.filtfun, querystring)) @registerCommand(MODE, 'namedqueries') diff --git a/alot/commands/taglist.py b/alot/commands/taglist.py index f5e8af73b..f71fc0323 100644 --- a/alot/commands/taglist.py +++ b/alot/commands/taglist.py @@ -13,6 +13,11 @@ class TaglistSelectCommand(Command): """search for messages with selected tag""" async def apply(self, ui): - tagstring = ui.current_buffer.get_selected_tag() - cmd = SearchCommand(query=['tag:"%s"' % tagstring]) + tagstring = 'tag:"%s"' % ui.current_buffer.get_selected_tag() + querystring = ui.current_buffer.querystring + if querystring: + fullquerystring = '(%s) AND %s' % (querystring, tagstring) + else: + fullquerystring = tagstring + cmd = SearchCommand(query=[fullquerystring]) await ui.apply_command(cmd)