Add a couple more states to match against

So we can now select windows/tabs that are not active/focused but are in
the active/focused tab/os window.
This commit is contained in:
Kovid Goyal 2022-04-12 20:35:31 +05:30
parent f15ce21da1
commit 2c72c56e22
No known key found for this signature in database
GPG key ID: 06BC317B515ACE7C
3 changed files with 12 additions and 2 deletions

View file

@ -90,7 +90,8 @@ def __call__(self, key: str, opt_name: Optional[str] = None, missing: Any = None
window and so on. When using the :italic:`env` field
to match on environment variables you can specify only the environment variable name or a name
and value, for example, :italic:`env:MY_ENV_VAR=2`. The field :code:`state` matches
on the state of the window. Supported states are: :code:`active`, :code:`focused` and :code:`needs_attention`.
on the state of the window. Supported states are:
:code:`active`, :code:`focused`, :code:`needs_attention`, :code:`parent_active` and :code:`parent_focused`.
Active windows are windows that are the active window in their parent tab. There is only one focused window
and it is the window to which keyboard events are delivered.
'''
@ -110,7 +111,8 @@ def __call__(self, key: str, opt_name: Optional[str] = None, missing: Any = None
is used to match the nth tab in the currently active OS window. The :code:`recent` number
matches recently active tabs in the currently active OS window, with zero being the currently
active tab, one the previously active tab and so on. The field :code:`state` matches
on the state of the tab. Supported states are: :code:`active`, :code:`focused` and :code:`needs_attention`.
on the state of the tab. Supported states are:
:code:`active`, :code:`focused`, :code:`needs_attention`, :code:`parent_active` and :code:`parent_focused`.
Active tabs are tabs that are the active tab in their parent OS Window. There is only one focused tab
and it is the tab to which keyboard events are delivered.
'''

View file

@ -717,6 +717,10 @@ def matches_query(self, field: str, query: str, active_tab_manager: Optional['Ta
for w in self:
if w.needs_attention:
return True
if query == 'parent_active':
return active_tab_manager is not None and self.tab_manager_ref() is active_tab_manager
if query == 'parent_focused':
return active_tab_manager is not None and self.tab_manager_ref() is active_tab_manager and self.os_window_id == current_os_window()
return False
return False

View file

@ -668,6 +668,10 @@ def matches_query(self, field: str, query: str, active_tab: Optional[TabType] =
return active_tab is not None and self is active_tab.active_window and current_os_window() == self.os_window_id
if query == 'needs_attention':
return self.needs_attention
if query == 'parent_active':
return active_tab is not None and self.tabref() is active_tab
if query == 'parent_focused':
return active_tab is not None and self.tabref() is active_tab and current_os_window() == self.os_window_id
return False
pat = compile_match_query(query, field != 'env')
return self.matches(field, pat)