Skip to content

Commit 46537e7

Browse files
committed
Allow matching tabs/windows over a custom all set
1 parent 21579e6 commit 46537e7

File tree

3 files changed

+16
-21
lines changed

3 files changed

+16
-21
lines changed

kitty/boss.py

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -532,17 +532,19 @@ def all_windows(self) -> Iterator[Window]:
532532
for tab in self.all_tabs:
533533
yield from tab
534534

535-
def match_windows(self, match: str, self_window: Optional['Window'] = None) -> Iterator[Window]:
535+
def match_windows(self, match: str, self_window: Optional['Window'] = None, all_windows: Iterable[Window] | None = None) -> Iterator[Window]:
536+
all_windows = self.all_windows if all_windows is None else all_windows
536537
if match == 'all':
537-
yield from self.all_windows
538+
yield from all_windows
538539
return
539540
from .search_query_parser import search
540541
tab = self.active_tab
541542
if current_focused_os_window_id() <= 0:
542543
tm = self.os_window_map.get(last_focused_os_window_id())
543544
if tm is not None:
544545
tab = tm.active_tab
545-
window_id_limit = max(self.window_id_map, default=-1) + 1
546+
wids = {w.id for w in all_windows}
547+
window_id_limit = max(wids, default=-1) + 1
546548
active_session = self.active_session
547549

548550
def get_matches(location: str, query: str, candidates: set[int]) -> set[int]:
@@ -557,25 +559,19 @@ def get_matches(location: str, query: str, candidates: set[int]) -> set[int]:
557559

558560
for wid in search(match, (
559561
'id', 'title', 'pid', 'cwd', 'cmdline', 'num', 'env', 'var', 'recent', 'state', 'neighbor', 'session',
560-
), set(self.window_id_map), get_matches):
562+
), wids, get_matches):
561563
yield self.window_id_map[wid]
562564

563-
def tab_for_window(self, window: Window) -> Tab | None:
564-
for tab in self.all_tabs:
565-
for w in tab:
566-
if w.id == window.id:
567-
return tab
568-
return None
569-
570-
def match_tabs(self, match: str) -> Iterator[Tab]:
565+
def match_tabs(self, match: str, all_tabs: Iterable[Tab] | None = None) -> Iterator[Tab]:
566+
all_tabs = self.all_tabs if all_tabs is None else all_tabs
571567
if match == 'all':
572-
yield from self.all_tabs
568+
yield from all_tabs
573569
return
574570
from .search_query_parser import search
575571
tm = self.active_tab_manager
576572
if current_focused_os_window_id() <= 0:
577573
tm = self.os_window_map.get(last_focused_os_window_id()) or tm
578-
tim = {t.id: t for t in self.all_tabs}
574+
tim = {t.id: t for t in all_tabs}
579575
tab_id_limit = max(tim, default=-1) + 1
580576
window_id_limit = max(self.window_id_map, default=-1) + 1
581577

@@ -592,13 +588,14 @@ def get_matches(location: str, query: str, candidates: set[int]) -> set[int]:
592588

593589
found = False
594590
for tid in search(match, (
595-
'id', 'index', 'title', 'window_id', 'window_title', 'pid', 'cwd', 'env', 'var', 'cmdline', 'recent', 'state', 'session',
591+
'id', 'index', 'title', 'window_id', 'window_title', 'pid', 'cwd', 'env', 'var',
592+
'cmdline', 'recent', 'state', 'session',
596593
), set(tim), get_matches):
597594
found = True
598595
yield tim[tid]
599596

600597
if not found:
601-
tabs = {self.tab_for_window(w) for w in self.match_windows(match)}
598+
tabs = {w.tabref() for w in self.match_windows(match)}
602599
for q in tabs:
603600
if q:
604601
yield q
@@ -3007,7 +3004,7 @@ def _move_window_to(
30073004
window = window or self.active_window
30083005
if not window:
30093006
return
3010-
src_tab = self.tab_for_window(window)
3007+
src_tab = window.tabref()
30113008
if src_tab is None:
30123009
return
30133010
with self.suppress_focus_change_events():

kitty/rc/base.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -390,8 +390,7 @@ def tabs_for_match_payload(self, boss: 'Boss', window: Optional['Window'], paylo
390390
raise MatchError(match, 'tabs')
391391
return tabs
392392
if window and payload_get('self') in (None, True):
393-
q = boss.tab_for_window(window)
394-
if q:
393+
if q := window.tabref():
395394
return [q]
396395
t = boss.active_tab
397396
if t:

kitty/window.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1467,8 +1467,7 @@ def add_kitten_result_processor(self, callback: Callable[['Window', Any], None])
14671467
self.kitten_result_processors.append(callback)
14681468

14691469
def handle_overlay_ready(self, msg: memoryview) -> None:
1470-
boss = get_boss()
1471-
tab = boss.tab_for_window(self)
1470+
tab = self.tabref()
14721471
if tab is not None:
14731472
tab.move_window_to_top_of_group(self)
14741473
if self.keys_redirected_till_ready_from:

0 commit comments

Comments
 (0)