Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion alot/buffers/namedqueries.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ def rebuild(self):

def focus_first(self):
"""Focus the first line in the query list."""
self.body.set_focus(0)
if self.queries:
self.body.set_focus(0)

def focus_last(self):
allpos = self.querylist.body.positions(reverse=True)
Expand Down
4 changes: 4 additions & 0 deletions alot/buffers/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,17 @@ def consume_pipe_until(self, predicate, limit=0):
n -= 1

def focus_first(self):
if self.body.focus is None: # no threads to move to
return
if not self.reversed:
self.body.set_focus(0)
else:
self.rebuild(reverse=False, restore_focus=False)
self.body.set_focus(0)

def focus_last(self):
if self.body.focus is None: # no threads to move to
return
if self.reversed:
self.body.set_focus(0)
elif self.search_threads_move_last_limit == 0 \
Expand Down
2 changes: 2 additions & 0 deletions tests/buffers/test_namedqueries.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ def test_no_queries(self, _):
ui = mock.Mock()
ui.dbman.get_named_queries.return_value = {}
buf = NamedQueriesBuffer(ui)
buf.focus_first() # nothing to move to
buf.focus_last()
ui.dbman.get_named_queries.return_value = {'q': 'tag:inbox'}
ui.dbman.count_messages.return_value = 0
buf.rebuild() # the first query appears
Expand Down
19 changes: 19 additions & 0 deletions tests/buffers/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import unittest
from unittest import mock

from notmuch2 import NotmuchError

from alot.buffers.search import SearchBuffer


Expand Down Expand Up @@ -46,3 +48,20 @@ def threadline(tid, dbman):
buf.rebuild()
# the focused thread was e.g. archived: nothing to look for
self.assertEqual(built, [])


@mock.patch('alot.buffers.search.settings', **{'get.return_value': 0})
class TestMoveInEmptyResults(unittest.TestCase):

def assertMovesWithoutError(self, get_threads):
ui = mock.Mock(**{'dbman.get_threads': get_threads})
buf = SearchBuffer(ui, 'tag:none')
buf.focus_first() # nothing to move to
buf.focus_last()

def test_no_results(self, _):
self.assertMovesWithoutError(
mock.Mock(return_value=(iter([]), 0)))

def test_malformed_query(self, _):
self.assertMovesWithoutError(mock.Mock(side_effect=NotmuchError))
Loading