mirror of
https://github.com/kovidgoyal/kitty.git
synced 2026-11-17 13:42:49 +00:00
Fix visual window select treating an empty allowed set as unrestricted
An empty only_window_ids meant every window was selectable, so for example select-window --exclude-active in a single window tab returned the active window. Use None to mean unrestricted instead. Closes #10683
This commit is contained in:
parent
c0b384f310
commit
22cfda44df
4 changed files with 40 additions and 8 deletions
|
|
@ -519,6 +519,10 @@ Detailed list of changes
|
|||
- :option:`launch --os-window-title`: Fix the value :code:`current` not copying
|
||||
a fixed title set with :option:`kitty --title`
|
||||
|
||||
- Visual window selection: Fix excluded windows becoming selectable when no
|
||||
other windows are eligible, for example, with
|
||||
:option:`kitten @ select-window --exclude-active` in a tab with a single window
|
||||
|
||||
|
||||
0.49.2 [2026-10-01]
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
|
|
|||
|
|
@ -1881,7 +1881,7 @@ class Boss:
|
|||
tab: Tab,
|
||||
callback: Callable[[Tab | None, Window | None], None],
|
||||
choose_msg: str,
|
||||
only_window_ids: Container[int] = (),
|
||||
only_window_ids: Container[int] | None = None,
|
||||
reactivate_prev_tab: bool = False,
|
||||
) -> None:
|
||||
import string
|
||||
|
|
@ -1906,7 +1906,7 @@ class Boss:
|
|||
fmap = get_name_to_functional_number_map()
|
||||
alphanumerics = get_options().visual_window_select_characters
|
||||
for idx, window in tab.windows.iter_windows_with_number(only_visible=True):
|
||||
if only_window_ids and window.id not in only_window_ids:
|
||||
if only_window_ids is not None and window.id not in only_window_ids:
|
||||
continue
|
||||
ac = KeyDefinition(definition=f'visual_window_select_action_trigger {window.id}')
|
||||
if idx >= len(alphanumerics):
|
||||
|
|
@ -1962,11 +1962,11 @@ class Boss:
|
|||
ev = WindowSystemMouseEvent(in_tab_bar, window_id, action, modifiers, button, currently_pressed_button, x, y)
|
||||
self.mouse_handler(ev)
|
||||
|
||||
def select_window_in_tab_using_overlay(self, tab: Tab, msg: str, only_window_ids: Container[int] = ()) -> Window | None:
|
||||
def select_window_in_tab_using_overlay(self, tab: Tab, msg: str, only_window_ids: Container[int] | None = None) -> Window | None:
|
||||
windows: list[tuple[int | None, str]] = []
|
||||
selectable_windows: list[tuple[int, str]] = []
|
||||
for i, w in tab.windows.iter_windows_with_number(only_visible=False):
|
||||
if only_window_ids and w.id not in only_window_ids:
|
||||
if only_window_ids is not None and w.id not in only_window_ids:
|
||||
windows.append((None, f'Current window: {w.title}' if w is self.active_window else w.title))
|
||||
else:
|
||||
windows.append((w.id, w.title))
|
||||
|
|
|
|||
|
|
@ -78,10 +78,7 @@ be refocused.
|
|||
|
||||
for tab in self.tabs_for_match_payload(boss, window, payload_get):
|
||||
if tab:
|
||||
if payload_get('exclude_active'):
|
||||
wids = tab.all_window_ids_except_active_window
|
||||
else:
|
||||
wids = set()
|
||||
wids = tab.all_window_ids_except_active_window if payload_get('exclude_active') else None
|
||||
boss.visual_window_select_action(
|
||||
tab, callback, payload_get('title') or 'Choose window', only_window_ids=wids, reactivate_prev_tab=payload_get('reactivate_prev_tab')
|
||||
)
|
||||
|
|
|
|||
|
|
@ -37,6 +37,37 @@ class Boss:
|
|||
|
||||
|
||||
class TestRemoteControl(BaseTest):
|
||||
def test_select_window_exclude_active(self):
|
||||
from kitty.boss import Boss as KittyBoss
|
||||
|
||||
command = command_for_name('select-window')
|
||||
for exclude_active in (False, True):
|
||||
with self.subTest(exclude_active=exclude_active):
|
||||
tab = Mock(all_window_ids_except_active_window=set())
|
||||
boss = Mock(active_tab=tab)
|
||||
args = ('select-window',) + (('--exclude-active',) if exclude_active else ())
|
||||
with patch.object(command, 'create_async_responder'):
|
||||
KittyBoss.call_remote_control(boss, None, args)
|
||||
self.ae(boss.visual_window_select_action.call_args.kwargs['only_window_ids'], set() if exclude_active else None)
|
||||
|
||||
def test_visual_window_select_empty_allowed_set(self):
|
||||
from kitty.boss import Boss as KittyBoss
|
||||
|
||||
self.set_options()
|
||||
for only_active_window_visible in (False, True):
|
||||
for only_window_ids, expected in ((set(), 0), (None, 1)):
|
||||
with self.subTest(only_active_window_visible=only_active_window_visible, only_window_ids=only_window_ids):
|
||||
window = Mock(id=1)
|
||||
tab = Mock(tab_manager_ref=Mock(return_value=None), os_window_id=1)
|
||||
tab.current_layout.only_active_window_visible = only_active_window_visible
|
||||
tab.windows.iter_windows_with_number.return_value = [(0, window)]
|
||||
boss = Mock()
|
||||
boss.select_window_in_tab_using_overlay = lambda *a: KittyBoss.select_window_in_tab_using_overlay(boss, *a)
|
||||
with patch('kitty.boss.current_os_window', return_value=1):
|
||||
KittyBoss.visual_window_select_action(boss, tab, Mock(), 'Choose', only_window_ids=only_window_ids)
|
||||
boss.visual_window_select_action_trigger.assert_called_once_with(expected)
|
||||
boss.choose_entry.assert_not_called()
|
||||
|
||||
def test_run_mapping_ignores_stdin(self):
|
||||
from kitty.boss import Boss as KittyBoss
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue