From 7cd033d8de60ec465fb353acc23e79d7b0ed6481 Mon Sep 17 00:00:00 2001 From: Pokey Rule <755842+pokey@users.noreply.github.com> Date: Sat, 10 Feb 2024 04:34:27 +0000 Subject: [PATCH] Fix broken cheatsheet if user has custom `"glyph"` spoken form (#2233) ## Checklist - [-] I have added [tests](https://www.cursorless.org/docs/contributing/test-case-recorder/) - [-] I have updated the [docs](https://github.com/cursorless-dev/cursorless/tree/main/docs) and [cheatsheet](https://github.com/cursorless-dev/cursorless/tree/main/cursorless-talon/src/cheatsheet) - [x] I have not broken the cheatsheet --------- Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com> --- cursorless-talon/src/cheatsheet/get_list.py | 15 +++++++++++++++ .../src/cheatsheet/sections/compound_targets.py | 14 ++++---------- .../src/cheatsheet/sections/scopes.py | 6 +++--- 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/cursorless-talon/src/cheatsheet/get_list.py b/cursorless-talon/src/cheatsheet/get_list.py index f60696bb9b..c74f364344 100644 --- a/cursorless-talon/src/cheatsheet/get_list.py +++ b/cursorless-talon/src/cheatsheet/get_list.py @@ -40,6 +40,21 @@ def get_raw_list(name: str) -> Mapping[str, str]: return registry.lists[cursorless_list_name][0].copy() +def get_spoken_form_from_list(list_name: str, value: str) -> str: + """Get the spoken form of a value from a list. + + Args: + list_name (str): The name of the list. + value (str): The value to look up. + + Returns: + str: The spoken form of the value. + """ + return next( + spoken_form for spoken_form, v in get_raw_list(list_name).items() if v == value + ) + + def make_dict_readable( type: str, dict: Mapping[str, str], descriptions: Mapping[str, str] ) -> list[ListItemDescriptor]: diff --git a/cursorless-talon/src/cheatsheet/sections/compound_targets.py b/cursorless-talon/src/cheatsheet/sections/compound_targets.py index faf7383d88..9f1b85b439 100644 --- a/cursorless-talon/src/cheatsheet/sections/compound_targets.py +++ b/cursorless-talon/src/cheatsheet/sections/compound_targets.py @@ -1,4 +1,4 @@ -from ..get_list import get_raw_list +from ..get_list import get_raw_list, get_spoken_form_from_list FORMATTERS = { "rangeExclusive": lambda start, end: f"between {start} and {end}", @@ -10,16 +10,10 @@ def get_compound_targets(): - list_connective_term = next( - spoken_form - for spoken_form, value in get_raw_list("list_connective").items() - if value == "listConnective" - ) - vertical_range_term = next( - spoken_form - for spoken_form, value in get_raw_list("range_type").items() - if value == "verticalRange" + list_connective_term = get_spoken_form_from_list( + "list_connective", "listConnective" ) + vertical_range_term = get_spoken_form_from_list("range_type", "verticalRange") return [ { diff --git a/cursorless-talon/src/cheatsheet/sections/scopes.py b/cursorless-talon/src/cheatsheet/sections/scopes.py index 9c610891fe..462074beae 100644 --- a/cursorless-talon/src/cheatsheet/sections/scopes.py +++ b/cursorless-talon/src/cheatsheet/sections/scopes.py @@ -1,8 +1,8 @@ -from ..get_list import get_lists, get_raw_list +from ..get_list import get_lists, get_spoken_form_from_list def get_scopes(): - complex_scopes = get_raw_list("glyph_scope_type") + glyph_spoken_form = get_spoken_form_from_list("glyph_scope_type", "glyph") return [ *get_lists( ["scope_type"], @@ -17,7 +17,7 @@ def get_scopes(): "type": "scopeType", "variations": [ { - "spokenForm": f"{complex_scopes['glyph']} ", + "spokenForm": f"{glyph_spoken_form} ", "description": "Instance of single character ", }, ],