summaryrefslogtreecommitdiff
path: root/alot/buffers
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2020-03-02 18:08:16 +0100
committerAnton Khirnov <anton@khirnov.net>2020-03-02 18:08:16 +0100
commitcd4a20552b33355f790379dcb4275f9105aea1b3 (patch)
treee0b25c9cb78617c7649c64060e4ba55075ae952d /alot/buffers
parentd035e850d3dde1fbc8d556861f7ef72d581c5506 (diff)
buffers/thread: add focusing on first/last message matching a property
Diffstat (limited to 'alot/buffers')
-rw-r--r--alot/buffers/thread.py28
1 files changed, 22 insertions, 6 deletions
diff --git a/alot/buffers/thread.py b/alot/buffers/thread.py
index c60b123c..eafd84b4 100644
--- a/alot/buffers/thread.py
+++ b/alot/buffers/thread.py
@@ -216,15 +216,26 @@ class ThreadBuffer(Buffer):
if next_focus >= 0 and next_focus < self.thread.total_messages:
self.set_focus(next_focus)
+ _DIR_NEXT = 0
+ _DIR_PREV = 1
+ _DIR_FIRST = 2
+ _DIR_LAST = 3
+
def _focus_property(self, prop, direction):
"""does a walk in the given direction and focuses the
first message that matches the given property"""
cur_pos = self.get_selected_message_position()
- if direction > 0:
- walk = range(cur_pos + 1, self.thread.total_messages)
- else:
+ if direction == self._DIR_NEXT:
+ walk = range(cur_pos + 1, self.thread.total_messages)
+ elif direction == self._DIR_FIRST:
+ walk = range(0, self.thread.total_messages)
+ elif direction == self._DIR_PREV:
walk = reversed(range(0, cur_pos))
+ elif direction == self._DIR_LAST:
+ walk = reversed(range(0, self.thread.total_messages))
+ else:
+ raise ValueError('Invalid focus_propery direction: ' + str(direction))
for pos in walk:
if prop(self._msg_widgets[pos]):
@@ -233,11 +244,16 @@ class ThreadBuffer(Buffer):
def focus_next_matching(self, querystring):
"""focus next matching message in depth first order"""
- self._focus_property(lambda x: x.get_message().matches(querystring), 1)
-
+ self._focus_property(lambda x: x.get_message().matches(querystring), self._DIR_NEXT)
def focus_prev_matching(self, querystring):
"""focus previous matching message in depth first order"""
- self._focus_property(lambda x: x.get_message().matches(querystring), -1)
+ self._focus_property(lambda x: x.get_message().matches(querystring), self._DIR_PREV)
+ def focus_first_matching(self, querystring):
+ """focus first matching message in depth first order"""
+ self._focus_property(lambda x: x.get_message().matches(querystring), self._DIR_FIRST)
+ def focus_last_matching(self, querystring):
+ """focus last matching message in depth first order"""
+ self._focus_property(lambda x: x.get_message().matches(querystring), self._DIR_LAST)
def focus_thread_widget(self):
"""set focus on the thread widget"""