From 71e0aab09ccc840cfe357fb2734f56432ce2bc7f 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 (without `--global`) 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 when the tag is `select`ed. In addition, introduce a new command `globalselect` which does a global search with the selected tag. The default key binding is `meta enter`, complementing the default binding `enter` for `select`. --- alot/buffers/taglist.py | 3 ++- alot/commands/globals.py | 5 ++++- alot/commands/taglist.py | 19 +++++++++++++++++-- alot/defaults/default.bindings | 1 + docs/source/usage/modes/taglist.rst | 9 ++++++++- 5 files changed, 32 insertions(+), 5 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 3698ccf55..1e0cceb7c 100644 --- a/alot/commands/globals.py +++ b/alot/commands/globals.py @@ -583,15 +583,18 @@ def __init__(self, filtfun=lambda x: True, tags=None, match=None, globally=False Command.__init__(self, **kwargs) def apply(self, ui): + querystring = None if self.tags: tags = self.tags elif (not self.globally) and isinstance(ui.current_buffer, buffers.SearchBuffer): tags = ui.dbman.collect_tags(ui.current_buffer.querystring) + querystring = ui.current_buffer.querystring elif (not self.globally) 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: # self.globally or otherBuffer tags = ui.dbman.get_all_tags() - 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..82ab74b38 100644 --- a/alot/commands/taglist.py +++ b/alot/commands/taglist.py @@ -11,8 +11,23 @@ @registerCommand(MODE, 'select') class TaglistSelectCommand(Command): + """search for messages with selected tag within original buffer""" + async def apply(self, ui): + 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) + + +@registerCommand(MODE, 'globalselect') +class TaglistGlobalSelectCommand(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() + cmd = SearchCommand(query=[tagstring]) await ui.apply_command(cmd) diff --git a/alot/defaults/default.bindings b/alot/defaults/default.bindings index ffca1bdc9..6688ef1bc 100644 --- a/alot/defaults/default.bindings +++ b/alot/defaults/default.bindings @@ -57,6 +57,7 @@ q = exit [taglist] enter = select + meta enter = globalselect [namedqueries] enter = select diff --git a/docs/source/usage/modes/taglist.rst b/docs/source/usage/modes/taglist.rst index 08917bb2b..c1eed6f48 100644 --- a/docs/source/usage/modes/taglist.rst +++ b/docs/source/usage/modes/taglist.rst @@ -5,10 +5,17 @@ Commands in 'taglist' mode -------------------------- The following commands are available in taglist mode: +.. _cmd.taglist.globalselect: + +.. describe:: globalselect + + search for messages with selected tag + + .. _cmd.taglist.select: .. describe:: select - search for messages with selected tag + search for messages with selected tag within original buffer