From ca6eff5b801a0c3931abc6388a5997f5762873b8 Mon Sep 17 00:00:00 2001 From: Alessandro Ceserani Date: Sat, 22 Apr 2023 16:45:30 -0500 Subject: [PATCH] fix(feat): Distinguish delim and no-delim in aliases with all mod characters MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit fixes a bug that converted a user defined alias with all modifier characters, e.g. `my_alias: o c | s` into a modifier for `left_option` + `left_control` + `left_shift`. This is a result of an oversight from a previous feat that focused on aliases with all symbols like `my_alias: ⌥ ⌃ ⇧`. In this case, it made sense to also add this to the `MODIFIER_ALIASES` dict, since this alias is composed of all aliases. However, I only considered cases like `my_alias: o c s` as an alias for all modifiers that used the standard single character aliases. I failed to consider that a user might want to make an alias for `left_opt` + `left_control` + `s`, or `m`, `c`, `o`, etc. The solution this commit introduces is to introduce a check for one of the valid non-whitespace delimiters, `|` or `-`. If one of those is present in the alias definition, then the final character will be translated as the alphabetic key it represents. So, `my_alias: o c | s` would be added as `left_opt` + `left_control` + `s`. If the final delimiter is only whitespace, e.g. `my_alias: o c s`, then it is assumed the user wants to make an all-modifier alias, so that will be translated as `left_option` + `left_control` + `left_shift`. --- karaml/user_aliases.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/karaml/user_aliases.py b/karaml/user_aliases.py index 7ab9a0c..81fe3c1 100644 --- a/karaml/user_aliases.py +++ b/karaml/user_aliases.py @@ -73,10 +73,18 @@ def process_alias_definition( alias_def, f"{alias}: {alias_def}" ) - if modifier_in_primary := ALIASES.get(primary_kc): - alias_primary_key_code = modifier_in_primary.key_code - else: - alias_primary_key_code = MODIFIERS.get(primary_kc) or primary_kc + alias_primary_key_code = ( + ALIASES.get(primary_kc) or + MODIFIER_ALIASES.get(primary_kc) or + # e.g. `s` counts as `left_shift` only if there's no + # non-whitspace delimiter in the alias definition, else it's `s` + MODIFIERS.get(primary_kc) if ( + MODIFIERS.get(primary_kc) and + not search(r"[-|].+$", alias_def) + ) else None or + + primary_kc + ) mod_key_codes = alias_mods.get("mandatory") if opt_mods := alias_mods.get("optional"):