Skip to content

Commit 48af95f

Browse files
committed
Fixes
1 parent 85bfcbf commit 48af95f

File tree

2 files changed

+34
-29
lines changed

2 files changed

+34
-29
lines changed

cursorless-talon/src/csv_overrides.py

Lines changed: 32 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from collections.abc import Container
33
from dataclasses import dataclass
44
from datetime import datetime
5+
from itertools import groupby
56
from pathlib import Path
67
from typing import Callable, Iterable, Optional, TypedDict
78

@@ -225,40 +226,41 @@ def update_dicts(
225226
# Create map with all default values
226227
results_map: dict[str, ResultsListEntry] = {}
227228
for list_name, obj in default_values.items():
228-
for key, value in obj.items():
229-
results_map[value] = {"key": key, "value": value, "list": list_name}
229+
for spoken, id in obj.items():
230+
results_map[id] = {"spoken": spoken, "id": id, "list": list_name}
230231

231232
# Update result with current values
232-
for key, value in current_values.items():
233+
for spoken, id in current_values.items():
233234
try:
234-
results_map[value]["key"] = key
235+
results_map[id]["spoken"] = spoken
235236
except KeyError:
236-
if value in extra_ignored_values:
237+
if id in extra_ignored_values:
237238
pass
238-
elif allow_unknown_values or value in extra_allowed_values:
239+
elif allow_unknown_values or id in extra_allowed_values:
239240
assert default_list_name is not None
240-
results_map[value] = {
241-
"key": key,
242-
"value": value,
241+
results_map[id] = {
242+
"spoken": spoken,
243+
"id": id,
243244
"list": default_list_name,
244245
}
245246
else:
246247
raise
247248

248249
spoken_form_entries = list(generate_spoken_forms(results_map.values()))
250+
print(f"spoken_form_entries: {spoken_form_entries}")
249251

250252
# Assign result to talon context list
251253
assign_lists_to_context(
252254
ctx,
253255
{
254-
**{res["list"]: {} for res in results_map.values()},
255-
**{
256-
spoken_form_entry.list_name: {
257-
spoken_form: spoken_form_entry.id
258-
for spoken_form in spoken_form_entry.spoken_forms
259-
}
260-
for spoken_form_entry in spoken_form_entries
261-
},
256+
list_name: {
257+
spoken_form: entry.id
258+
for entry in spoken_form_entries
259+
for spoken_form in entry.spoken_forms
260+
}
261+
for list_name, spoken_form_entries in groupby(
262+
spoken_form_entries, key=lambda x: x.list_name
263+
)
262264
},
263265
pluralize_lists,
264266
)
@@ -268,33 +270,33 @@ def update_dicts(
268270

269271

270272
class ResultsListEntry(TypedDict):
271-
key: str
272-
value: str
273+
spoken: str
274+
id: str
273275
list: str
274276

275277

276278
def generate_spoken_forms(results_list: Iterable[ResultsListEntry]):
277279
for obj in results_list:
278-
value = obj["value"]
279-
key = obj["key"]
280+
id = obj["id"]
281+
spoken = obj["spoken"]
280282

281-
spoken = []
282-
if not is_removed(key):
283-
for k in key.split("|"):
284-
if value == "pasteFromClipboard" and k.endswith(" to"):
283+
spoken_forms = []
284+
if not is_removed(spoken):
285+
for k in spoken.split("|"):
286+
if id == "pasteFromClipboard" and k.endswith(" to"):
285287
# FIXME: This is a hack to work around the fact that the
286288
# spoken form of the `pasteFromClipboard` action used to be
287289
# "paste to", but now the spoken form is just "paste" and
288290
# the "to" is part of the positional target. Users who had
289291
# cursorless before this change would have "paste to" as
290292
# their spoken form and so would need to say "paste to to".
291293
k = k[:-3]
292-
spoken.append(k.strip())
294+
spoken_forms.append(k.strip())
293295

294296
yield SpokenFormEntry(
295-
obj["list"],
296-
value,
297-
spoken,
297+
list_name=obj["list"],
298+
id=id,
299+
spoken_forms=spoken_forms,
298300
)
299301

300302

@@ -303,6 +305,7 @@ def assign_lists_to_context(
303305
lists: ListToSpokenForms,
304306
pluralize_lists: list[str],
305307
):
308+
print(f"lists: {lists}")
306309
for list_name, dict in lists.items():
307310
list_singular_name = get_cursorless_list_name(list_name)
308311
ctx.lists[list_singular_name] = dict

cursorless-talon/src/spoken_forms.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ def update():
8282
spoken_forms = json.load(file)
8383

8484
initialized = False
85+
86+
# Maps from csv name to list of SpokenFormEntry
8587
custom_spoken_forms: dict[str, list[SpokenFormEntry]] = {}
8688
spoken_forms_output = SpokenFormsOutput()
8789
spoken_forms_output.init()

0 commit comments

Comments
 (0)