Skip to content

Commit

Permalink
Allow spaces in --when-focus-on
Browse files Browse the repository at this point in the history
  • Loading branch information
kovidgoyal committed Dec 2, 2023
1 parent 3c4f2aa commit 847ef00
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
6 changes: 2 additions & 4 deletions kitty/options/definition.py
Original file line number Diff line number Diff line change
Expand Up @@ -3452,7 +3452,7 @@
You can create mappings that apply when the focused window matches some condition,
such as having a particular program running. For example::
map --when-focus-on title:keyboard.protocol kitty_mod+t
map --when-focus-on "title:keyboard.protocol" kitty_mod+t
This will cause :kbd:`kitty_mod+t` (the default shortcut for opening a new tab)
to be unmapped only when the focused window
Expand All @@ -3463,9 +3463,7 @@
and press :kbd:`ctrl+shift+t` and instead of a new tab opening, you will
see the key press being reported by the kitten. :code:`--when-focus-on` can test
the focused window using very powerful criteria, see :ref:`search_syntax` for
details. Note that spaces are not allowed in the argument of --when-focus-on.
Use the . character or :code:`\\\\s` to match spaces.
A more practical example unmaps the key when the focused window is running vim::
details. A more practical example unmaps the key when the focused window is running vim::
map --when-focus-on var:in_editor
Expand Down
16 changes: 9 additions & 7 deletions kitty/options/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
unit_float,
)
from kitty.constants import is_macos
from kitty.fast_data_types import CURSOR_BEAM, CURSOR_BLOCK, CURSOR_UNDERLINE, Color, SingleKey
from kitty.fast_data_types import CURSOR_BEAM, CURSOR_BLOCK, CURSOR_UNDERLINE, Color, Shlex, SingleKey
from kitty.fonts import FontFeature, FontModification, ModificationType, ModificationUnit, ModificationValue
from kitty.key_names import character_key_name_aliases, functional_key_name_aliases, get_key_name_lookup
from kitty.rgb import color_as_int
Expand Down Expand Up @@ -1212,11 +1212,12 @@ def __init__(self, name: str = '') -> None:
KeyboardModeMap = Dict[str, KeyboardMode]


def parse_options_for_map(val: str) -> Tuple[KeyMapOptions, List[str]]:
def parse_options_for_map(val: str) -> Tuple[KeyMapOptions, str]:
expecting_arg = ''
ans = KeyMapOptions()
parts = val.split()
for i, x in enumerate(parts):
s = Shlex(val)
while (tok := s.next_word())[0] > -1:
x = tok[1]
if expecting_arg:
object.__setattr__(ans, expecting_arg, x)
expecting_arg = ''
Expand All @@ -1231,8 +1232,8 @@ def parse_options_for_map(val: str) -> Tuple[KeyMapOptions, List[str]]:
object.__setattr__(ans, k, v)
expecting_arg = ''
else:
return ans, parts[i:]
return ans, []
return ans, val[tok[0]:]
return ans, ''


def parse_map(val: str) -> Iterable[KeyDefinition]:
Expand All @@ -1241,7 +1242,8 @@ def parse_map(val: str) -> Iterable[KeyDefinition]:
if len(parts) == 2:
sc, action = parts
if sc.startswith('--'):
options, parts = parse_options_for_map(val)
options, leftover = parse_options_for_map(val)
parts = leftover.split(maxsplit=1)
if len(parts) == 1:
sc, action = parts[0], ''
else:
Expand Down

0 comments on commit 847ef00

Please sign in to comment.