Skip to content

Commit

Permalink
taglist: refine search from buffer
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mjg committed Oct 23, 2020
1 parent 49065ac commit 9b6d168
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
3 changes: 2 additions & 1 deletion alot/buffers/taglist.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 5 additions & 1 deletion alot/commands/globals.py
Original file line number Diff line number Diff line change
Expand Up @@ -579,24 +579,28 @@ 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)
if blists:
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')
Expand Down
9 changes: 7 additions & 2 deletions alot/commands/taglist.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 9b6d168

Please sign in to comment.