Skip to content

Commit

Permalink
Fix broken cheatsheet if user has custom "glyph" spoken form (#2233)
Browse files Browse the repository at this point in the history
## 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>
  • Loading branch information
pokey and pre-commit-ci-lite[bot] authored Feb 10, 2024
1 parent c5a3681 commit 7cd033d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 13 deletions.
15 changes: 15 additions & 0 deletions cursorless-talon/src/cheatsheet/get_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Expand Down
14 changes: 4 additions & 10 deletions cursorless-talon/src/cheatsheet/sections/compound_targets.py
Original file line number Diff line number Diff line change
@@ -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}",
Expand All @@ -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 [
{
Expand Down
6 changes: 3 additions & 3 deletions cursorless-talon/src/cheatsheet/sections/scopes.py
Original file line number Diff line number Diff line change
@@ -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"],
Expand All @@ -17,7 +17,7 @@ def get_scopes():
"type": "scopeType",
"variations": [
{
"spokenForm": f"{complex_scopes['glyph']} <character>",
"spokenForm": f"{glyph_spoken_form} <character>",
"description": "Instance of single character <character>",
},
],
Expand Down

0 comments on commit 7cd033d

Please sign in to comment.