From 7fc45728a91470d33102de7188c5ed56ab53706b Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Thu, 20 Feb 2014 20:47:06 +0100 Subject: [PATCH] NeighborList: add firstitem() and lastitem() --- qutebrowser/utils/types.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/qutebrowser/utils/types.py b/qutebrowser/utils/types.py index dd46d8f86..585a57b9e 100644 --- a/qutebrowser/utils/types.py +++ b/qutebrowser/utils/types.py @@ -114,6 +114,20 @@ class NeighborList: """Get the previous item in the list.""" return self.getitem(-1) + def firstitem(self): + """Get the first item in the list.""" + if not self._items: + raise IndexError("No items found!") + self.idx = 0 + return self.curitem() + + def lastitem(self): + """Get the last item in the list.""" + if not self._items: + raise IndexError("No items found!") + self.idx = len(self._items) - 1 + return self.curitem() + def reset(self): """Reset the position to the default.""" if self._default is _UNSET: