From cd4a20552b33355f790379dcb4275f9105aea1b3 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Mon, 2 Mar 2020 18:08:16 +0100 Subject: buffers/thread: add focusing on first/last message matching a property --- alot/buffers/thread.py | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) (limited to 'alot/buffers') 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""" -- cgit v1.2.3