Skip to content

Commit 0ed8040

Browse files
AndreasArvidssonpre-commit-ci-lite[bot]pokey
authored
Migrated surrounding pair scope handler (#2457)
Fixes #2316 ## Checklist - [x] 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 - [x] Add `@disqualifyDelimiter` for all languages - [x] Add plural form of surrounding pair [scopes.py](https://github.com/cursorless-dev/cursorless/blob/5e9a2e955570cb43d5d07de8c861365e8361cc36/cursorless-talon/src/modifiers/scopes.py#L48) - [x] Run talon tests - [x] add multiline quad tests for plaintext? --------- Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com> Co-authored-by: Pokey Rule <[email protected]>
1 parent d7fe84b commit 0ed8040

File tree

5 files changed

+87
-17
lines changed

5 files changed

+87
-17
lines changed

src/modifiers/modifiers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def cursorless_simple_modifier(m) -> dict[str, str]:
2727
"<user.cursorless_simple_scope_modifier>", # funk, state, class, every funk
2828
"<user.cursorless_ordinal_scope>", # first past second word
2929
"<user.cursorless_relative_scope>", # next funk, 3 funks
30-
"<user.cursorless_surrounding_pair>", # matching/pair [curly, round]
30+
"<user.cursorless_surrounding_pair_force_direction>", # DEPRECATED "left quad" / "right quad"
3131
]
3232

3333
modifiers = [

src/modifiers/scopes.py

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@
1515

1616

1717
@mod.capture(
18-
rule="{user.cursorless_scope_type} | <user.cursorless_glyph_scope_type> | {user.cursorless_custom_regex_scope_type}"
18+
rule="{user.cursorless_scope_type}"
19+
" | <user.cursorless_surrounding_pair_scope_type>"
20+
" | <user.cursorless_glyph_scope_type>"
21+
" | {user.cursorless_custom_regex_scope_type}"
1922
)
2023
def cursorless_scope_type(m) -> dict[str, str]:
2124
"""Cursorless scope type singular"""
@@ -24,16 +27,27 @@ def cursorless_scope_type(m) -> dict[str, str]:
2427
except AttributeError:
2528
pass
2629

30+
try:
31+
return m.cursorless_surrounding_pair_scope_type
32+
except AttributeError:
33+
pass
34+
2735
try:
2836
return m.cursorless_glyph_scope_type
2937
except AttributeError:
3038
pass
3139

32-
return {"type": "customRegex", "regex": m.cursorless_custom_regex_scope_type}
40+
return {
41+
"type": "customRegex",
42+
"regex": m.cursorless_custom_regex_scope_type,
43+
}
3344

3445

3546
@mod.capture(
36-
rule="{user.cursorless_scope_type_plural} | <user.cursorless_glyph_scope_type_plural> | {user.cursorless_custom_regex_scope_type_plural}"
47+
rule="{user.cursorless_scope_type_plural}"
48+
" | <user.cursorless_surrounding_pair_scope_type_plural>"
49+
" | <user.cursorless_glyph_scope_type_plural>"
50+
" | {user.cursorless_custom_regex_scope_type_plural}"
3751
)
3852
def cursorless_scope_type_plural(m) -> dict[str, str]:
3953
"""Cursorless scope type plural"""
@@ -42,6 +56,11 @@ def cursorless_scope_type_plural(m) -> dict[str, str]:
4256
except AttributeError:
4357
pass
4458

59+
try:
60+
return m.cursorless_surrounding_pair_scope_type_plural
61+
except AttributeError:
62+
pass
63+
4564
try:
4665
return m.cursorless_glyph_scope_type_plural
4766
except AttributeError:

src/modifiers/surrounding_pair.py

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@
2222
"cursorless_surrounding_pair_scope_type",
2323
desc="Scope types that can function as surrounding pairs",
2424
)
25+
mod.list(
26+
"cursorless_surrounding_pair_scope_type_plural",
27+
desc="Plural form of scope types that can function as surrounding pairs",
28+
)
2529

2630

2731
@mod.capture(
@@ -30,29 +34,43 @@
3034
"{user.cursorless_surrounding_pair_scope_type}"
3135
)
3236
)
33-
def cursorless_surrounding_pair_scope_type(m) -> str:
37+
def cursorless_surrounding_pair_scope_type(m) -> dict[str, str]:
3438
"""Surrounding pair scope type"""
3539
try:
36-
return m.cursorless_surrounding_pair_scope_type
40+
delimiter = m.cursorless_surrounding_pair_scope_type
3741
except AttributeError:
38-
return m.cursorless_selectable_paired_delimiter
42+
delimiter = m.cursorless_selectable_paired_delimiter
43+
return {
44+
"type": "surroundingPair",
45+
"delimiter": delimiter,
46+
}
3947

4048

4149
@mod.capture(
42-
rule="[{user.cursorless_delimiter_force_direction}] <user.cursorless_surrounding_pair_scope_type>"
50+
rule=(
51+
"<user.cursorless_selectable_paired_delimiter_plural> |"
52+
"{user.cursorless_surrounding_pair_scope_type_plural}"
53+
)
4354
)
44-
def cursorless_surrounding_pair(m) -> dict[str, Any]:
45-
"""Expand to containing surrounding pair"""
55+
def cursorless_surrounding_pair_scope_type_plural(m) -> dict[str, str]:
56+
"""Plural surrounding pair scope type"""
4657
try:
47-
surrounding_pair_scope_type = m.cursorless_surrounding_pair_scope_type
58+
delimiter = m.cursorless_surrounding_pair_scope_type_plural
4859
except AttributeError:
49-
surrounding_pair_scope_type = "any"
50-
51-
scope_type = {
60+
delimiter = m.cursorless_selectable_paired_delimiter_plural
61+
return {
5262
"type": "surroundingPair",
53-
"delimiter": surrounding_pair_scope_type,
63+
"delimiter": delimiter,
5464
}
5565

66+
67+
@mod.capture(
68+
rule="{user.cursorless_delimiter_force_direction} <user.cursorless_surrounding_pair_scope_type>"
69+
)
70+
def cursorless_surrounding_pair_force_direction(m) -> dict[str, Any]:
71+
"""DEPRECATED: Expand to containing surrounding pair"""
72+
scope_type = m.cursorless_surrounding_pair_scope_type
73+
5674
with suppress(AttributeError):
5775
scope_type["forceDirection"] = m.cursorless_delimiter_force_direction
5876

src/paired_delimiter.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,15 @@
1515
desc="A paired delimiter that can be used as a scope type and as a wrapper",
1616
)
1717

18+
mod.list(
19+
"cursorless_selectable_only_paired_delimiter_plural",
20+
desc="Plural form of a paired delimiter that can only be used as a scope type",
21+
)
22+
mod.list(
23+
"cursorless_wrapper_selectable_paired_delimiter_plural",
24+
desc="Plural form of a paired delimiter that can be used as a scope type and as a wrapper",
25+
)
26+
1827
# Maps from the id we use in the spoken form csv to the delimiter strings
1928
paired_delimiters = {
2029
"curlyBrackets": ["{", "}"],
@@ -58,3 +67,16 @@ def cursorless_selectable_paired_delimiter(m) -> str:
5867
return m.cursorless_selectable_only_paired_delimiter
5968
except AttributeError:
6069
return m.cursorless_wrapper_selectable_paired_delimiter
70+
71+
72+
@mod.capture(
73+
rule=(
74+
"{user.cursorless_selectable_only_paired_delimiter_plural} |"
75+
"{user.cursorless_wrapper_selectable_paired_delimiter_plural}"
76+
)
77+
)
78+
def cursorless_selectable_paired_delimiter_plural(m) -> str:
79+
try:
80+
return m.cursorless_selectable_only_paired_delimiter_plural
81+
except AttributeError:
82+
return m.cursorless_wrapper_selectable_paired_delimiter_plural

src/spoken_forms.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,18 +133,29 @@ def handle_new_values(csv_name: str, values: list[SpokenFormEntry]):
133133
handle_csv("target_connectives.csv"),
134134
handle_csv("modifiers.csv"),
135135
handle_csv("positions.csv"),
136-
handle_csv("paired_delimiters.csv"),
136+
handle_csv(
137+
"paired_delimiters.csv",
138+
pluralize_lists=[
139+
"selectable_only_paired_delimiter",
140+
"wrapper_selectable_paired_delimiter",
141+
],
142+
),
137143
handle_csv("special_marks.csv"),
138144
handle_csv("scope_visualizer.csv"),
139145
handle_csv("experimental/experimental_actions.csv"),
140146
handle_csv("experimental/miscellaneous.csv"),
141147
handle_csv(
142148
"modifier_scope_types.csv",
143-
pluralize_lists=["scope_type", "glyph_scope_type"],
149+
pluralize_lists=[
150+
"scope_type",
151+
"glyph_scope_type",
152+
"surrounding_pair_scope_type",
153+
],
144154
extra_allowed_values=[
145155
"private.fieldAccess",
146156
"private.switchStatementSubject",
147157
"textFragment",
158+
"disqualifyDelimiter",
148159
],
149160
default_list_name="scope_type",
150161
),

0 commit comments

Comments
 (0)