Allow matching tabs/windows over a custom all set

This commit is contained in:
Kovid Goyal
2025-08-23 14:05:41 +05:30
parent 21579e6fcb
commit 46537e76a5
3 changed files with 16 additions and 21 deletions

View File

@@ -532,9 +532,10 @@ class Boss:
for tab in self.all_tabs: for tab in self.all_tabs:
yield from tab yield from tab
def match_windows(self, match: str, self_window: Optional['Window'] = None) -> Iterator[Window]: def match_windows(self, match: str, self_window: Optional['Window'] = None, all_windows: Iterable[Window] | None = None) -> Iterator[Window]:
all_windows = self.all_windows if all_windows is None else all_windows
if match == 'all': if match == 'all':
yield from self.all_windows yield from all_windows
return return
from .search_query_parser import search from .search_query_parser import search
tab = self.active_tab tab = self.active_tab
@@ -542,7 +543,8 @@ class Boss:
tm = self.os_window_map.get(last_focused_os_window_id()) tm = self.os_window_map.get(last_focused_os_window_id())
if tm is not None: if tm is not None:
tab = tm.active_tab tab = tm.active_tab
window_id_limit = max(self.window_id_map, default=-1) + 1 wids = {w.id for w in all_windows}
window_id_limit = max(wids, default=-1) + 1
active_session = self.active_session active_session = self.active_session
def get_matches(location: str, query: str, candidates: set[int]) -> set[int]: def get_matches(location: str, query: str, candidates: set[int]) -> set[int]:
@@ -557,25 +559,19 @@ class Boss:
for wid in search(match, ( for wid in search(match, (
'id', 'title', 'pid', 'cwd', 'cmdline', 'num', 'env', 'var', 'recent', 'state', 'neighbor', 'session', 'id', 'title', 'pid', 'cwd', 'cmdline', 'num', 'env', 'var', 'recent', 'state', 'neighbor', 'session',
), set(self.window_id_map), get_matches): ), wids, get_matches):
yield self.window_id_map[wid] yield self.window_id_map[wid]
def tab_for_window(self, window: Window) -> Tab | None: def match_tabs(self, match: str, all_tabs: Iterable[Tab] | None = None) -> Iterator[Tab]:
for tab in self.all_tabs: all_tabs = self.all_tabs if all_tabs is None else all_tabs
for w in tab:
if w.id == window.id:
return tab
return None
def match_tabs(self, match: str) -> Iterator[Tab]:
if match == 'all': if match == 'all':
yield from self.all_tabs yield from all_tabs
return return
from .search_query_parser import search from .search_query_parser import search
tm = self.active_tab_manager tm = self.active_tab_manager
if current_focused_os_window_id() <= 0: if current_focused_os_window_id() <= 0:
tm = self.os_window_map.get(last_focused_os_window_id()) or tm tm = self.os_window_map.get(last_focused_os_window_id()) or tm
tim = {t.id: t for t in self.all_tabs} tim = {t.id: t for t in all_tabs}
tab_id_limit = max(tim, default=-1) + 1 tab_id_limit = max(tim, default=-1) + 1
window_id_limit = max(self.window_id_map, default=-1) + 1 window_id_limit = max(self.window_id_map, default=-1) + 1
@@ -592,13 +588,14 @@ class Boss:
found = False found = False
for tid in search(match, ( for tid in search(match, (
'id', 'index', 'title', 'window_id', 'window_title', 'pid', 'cwd', 'env', 'var', 'cmdline', 'recent', 'state', 'session', 'id', 'index', 'title', 'window_id', 'window_title', 'pid', 'cwd', 'env', 'var',
'cmdline', 'recent', 'state', 'session',
), set(tim), get_matches): ), set(tim), get_matches):
found = True found = True
yield tim[tid] yield tim[tid]
if not found: if not found:
tabs = {self.tab_for_window(w) for w in self.match_windows(match)} tabs = {w.tabref() for w in self.match_windows(match)}
for q in tabs: for q in tabs:
if q: if q:
yield q yield q
@@ -3007,7 +3004,7 @@ class Boss:
window = window or self.active_window window = window or self.active_window
if not window: if not window:
return return
src_tab = self.tab_for_window(window) src_tab = window.tabref()
if src_tab is None: if src_tab is None:
return return
with self.suppress_focus_change_events(): with self.suppress_focus_change_events():

View File

@@ -390,8 +390,7 @@ class RemoteCommand:
raise MatchError(match, 'tabs') raise MatchError(match, 'tabs')
return tabs return tabs
if window and payload_get('self') in (None, True): if window and payload_get('self') in (None, True):
q = boss.tab_for_window(window) if q := window.tabref():
if q:
return [q] return [q]
t = boss.active_tab t = boss.active_tab
if t: if t:

View File

@@ -1467,8 +1467,7 @@ class Window:
self.kitten_result_processors.append(callback) self.kitten_result_processors.append(callback)
def handle_overlay_ready(self, msg: memoryview) -> None: def handle_overlay_ready(self, msg: memoryview) -> None:
boss = get_boss() tab = self.tabref()
tab = boss.tab_for_window(self)
if tab is not None: if tab is not None:
tab.move_window_to_top_of_group(self) tab.move_window_to_top_of_group(self)
if self.keys_redirected_till_ready_from: if self.keys_redirected_till_ready_from: