Matching windows/tabs: allow matching by recency

``recent:0`` matches the active window/tab, ``recent:1`` matches the
previous window/tab and so on
This commit is contained in:
Kovid Goyal
2021-08-16 18:29:06 +05:30
parent c00e945f6e
commit 4333552523
4 changed files with 48 additions and 6 deletions

View File

@@ -511,6 +511,12 @@ class Tab: # {{{
if groups:
return groups[0]
def nth_active_window_id(self, n: int = 0) -> int:
if n <= 0:
return self.active_window.id if self.active_window else 0
ids = tuple(reversed(self.windows.active_window_history))
return ids[min(n - 1, len(ids) - 1)] if ids else 0
def neighboring_group_id(self, which: EdgeLiteral) -> Optional[int]:
neighbors = self.current_layout.neighbors(self.windows)
candidates = neighbors.get(which)
@@ -748,6 +754,12 @@ class TabManager: # {{{
self.set_active_tab_idx(idx)
break
def nth_active_tab(self, n: int = 0) -> Optional[Tab]:
if n <= 0:
return self.active_tab
tab_ids = tuple(reversed(self.active_tab_history))
return self.tab_for_id(tab_ids[min(n - 1, len(tab_ids) - 1)]) if tab_ids else None
def __iter__(self) -> Iterator[Tab]:
return iter(self.tabs)