Skip to content

Commit e61b532

Browse files
Merge branch 'main' into collectionItemScopeProvider
2 parents da66455 + 1bffae5 commit e61b532

File tree

29 files changed

+650
-143
lines changed

29 files changed

+650
-143
lines changed

cursorless-everywhere-talon/cursorless_everywhere_talon.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
tag: user.cursorless_everywhere_talon
1515
"""
1616

17+
ctx.tags = ["user.cursorless"]
18+
1719

1820
@ctx.action_class("user")
1921
class UserActions:
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
from talon import Context, Module, actions
2+
3+
from .cursorless_everywhere_types import EditorEdit, EditorState, SelectionOffsets
4+
5+
mod = Module()
6+
7+
mod.tag(
8+
"cursorless_everywhere_talon_browser",
9+
desc="Enable RPC to browser extension when using cursorless everywhere in Talon",
10+
)
11+
12+
ctx = Context()
13+
ctx.matches = r"""
14+
tag: user.cursorless_everywhere_talon_browser
15+
"""
16+
17+
RPC_COMMAND = "talonCommand"
18+
19+
20+
@ctx.action_class("user")
21+
class Actions:
22+
def cursorless_everywhere_get_editor_state() -> EditorState:
23+
command = {
24+
"id": "getEditorState",
25+
}
26+
res = rpc_get(command)
27+
if use_fallback(res):
28+
return actions.next()
29+
return res
30+
31+
def cursorless_everywhere_set_selections(
32+
selections: list[SelectionOffsets], # pyright: ignore [reportGeneralTypeIssues]
33+
):
34+
command = {
35+
"id": "setSelections",
36+
"selections": get_serializable_selections(selections),
37+
}
38+
res = rpc_get(command)
39+
if use_fallback(res):
40+
actions.next(selections)
41+
42+
def cursorless_everywhere_edit_text(
43+
edit: EditorEdit, # pyright: ignore [reportGeneralTypeIssues]
44+
):
45+
command = {
46+
"id": "setText",
47+
"text": edit["text"],
48+
}
49+
res = rpc_get(command)
50+
if use_fallback(res):
51+
actions.next(edit)
52+
53+
54+
def rpc_get(command: dict):
55+
return actions.user.run_rpc_command_get(RPC_COMMAND, command)
56+
57+
58+
def use_fallback(result: dict) -> bool:
59+
return result.get("fallback", False)
60+
61+
62+
# What is passed from cursorless everywhere js is a javascript object, which is not serializable for python.
63+
def get_serializable_selections(selections: list[SelectionOffsets]):
64+
result: list[SelectionOffsets] = []
65+
for i in range(selections.length): # pyright: ignore [reportAttributeAccessIssue]
66+
selection = selections[i]
67+
result.append(
68+
{
69+
"anchor": selection["anchor"],
70+
"active": selection["active"],
71+
}
72+
)
73+
return result
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Please file pull requests to the cursorless-talon subdirectory in the https://github.com/cursorless-dev/cursorless repo

cursorless-talon/src/check_community_repo.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,10 @@ def on_ready():
2626
if missing_actions:
2727
errors.append(f"Missing actions: {', '.join(missing_actions)}")
2828
if errors:
29+
print("Cursorless community requirements:")
2930
print("\n".join(errors))
3031
app.notify(
31-
"Please install the community repository",
32+
"Cursorless: Please install the community repository",
3233
body="https://github.com/talonhub/community",
3334
)
3435

cursorless-talon/src/cursorless.talon

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,5 @@ tutorial (previous | last): user.private_cursorless_tutorial_previous()
4545
tutorial restart: user.private_cursorless_tutorial_restart()
4646
tutorial resume: user.private_cursorless_tutorial_resume()
4747
tutorial (list | close): user.private_cursorless_tutorial_list()
48-
tutorial <user.private_cursorless_number_small>:
49-
user.private_cursorless_tutorial_start_by_number(private_cursorless_number_small)
48+
tutorial <number_small>:
49+
user.private_cursorless_tutorial_start_by_number(number_small)

cursorless-talon/src/marks/lines_number.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ class CustomizableTerm:
3131

3232
@mod.capture(
3333
rule=(
34-
"{user.cursorless_line_direction} <user.private_cursorless_number_small> "
35-
"[<user.cursorless_range_connective> <user.private_cursorless_number_small>]"
34+
"{user.cursorless_line_direction} <number_small> "
35+
"[<user.cursorless_range_connective> <number_small>]"
3636
)
3737
)
3838
def cursorless_line_number(m) -> LineNumber:
3939
direction = directions_map[m.cursorless_line_direction]
40-
numbers: list[int] = m.private_cursorless_number_small_list
40+
numbers: list[int] = m.number_small_list
4141
anchor = create_line_number_mark(direction.type, direction.formatter(numbers[0]))
4242
if len(numbers) > 1:
4343
active = create_line_number_mark(

cursorless-talon/src/modifiers/ordinal_scope.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def cursorless_ordinal_range(m) -> dict[str, Any]:
4747
rule=(
4848
"[{user.cursorless_every_scope_modifier}] "
4949
"({user.cursorless_first_modifier} | {user.cursorless_last_modifier}) "
50-
"<user.private_cursorless_number_small> <user.cursorless_scope_type_plural>"
50+
"<number_small> <user.cursorless_scope_type_plural>"
5151
),
5252
)
5353
def cursorless_first_last(m) -> dict[str, Any]:
@@ -57,13 +57,13 @@ def cursorless_first_last(m) -> dict[str, Any]:
5757
return create_ordinal_scope_modifier(
5858
m.cursorless_scope_type_plural,
5959
0,
60-
m.private_cursorless_number_small,
60+
m.number_small,
6161
is_every,
6262
)
6363
return create_ordinal_scope_modifier(
6464
m.cursorless_scope_type_plural,
65-
-m.private_cursorless_number_small,
66-
m.private_cursorless_number_small,
65+
-m.number_small,
66+
m.number_small,
6767
is_every,
6868
)
6969

cursorless-talon/src/modifiers/relative_scope.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,28 +31,28 @@ def cursorless_relative_scope_singular(m) -> dict[str, Any]:
3131

3232

3333
@mod.capture(
34-
rule="[{user.cursorless_every_scope_modifier}] <user.cursorless_relative_direction> <user.private_cursorless_number_small> <user.cursorless_scope_type_plural>"
34+
rule="[{user.cursorless_every_scope_modifier}] <user.cursorless_relative_direction> <number_small> <user.cursorless_scope_type_plural>"
3535
)
3636
def cursorless_relative_scope_plural(m) -> dict[str, Any]:
3737
"""Relative previous/next plural scope. `next three funks`"""
3838
return create_relative_scope_modifier(
3939
m.cursorless_scope_type_plural,
4040
1,
41-
m.private_cursorless_number_small,
41+
m.number_small,
4242
m.cursorless_relative_direction,
4343
hasattr(m, "cursorless_every_scope_modifier"),
4444
)
4545

4646

4747
@mod.capture(
48-
rule="[{user.cursorless_every_scope_modifier}] <user.private_cursorless_number_small> <user.cursorless_scope_type_plural> [{user.cursorless_forward_backward_modifier}]"
48+
rule="[{user.cursorless_every_scope_modifier}] <number_small> <user.cursorless_scope_type_plural> [{user.cursorless_forward_backward_modifier}]"
4949
)
5050
def cursorless_relative_scope_count(m) -> dict[str, Any]:
5151
"""Relative count scope. `three funks`"""
5252
return create_relative_scope_modifier(
5353
m.cursorless_scope_type_plural,
5454
0,
55-
m.private_cursorless_number_small,
55+
m.number_small,
5656
getattr(m, "cursorless_forward_backward_modifier", "forward"),
5757
hasattr(m, "cursorless_every_scope_modifier"),
5858
)
Lines changed: 10 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,20 @@
11
"""
2-
This file allows us to use a custom `number_small` capture. See #1021 for more
3-
info.
2+
DEPRECATED @ 2024-12-21
3+
This file allows us to use a custom `number_small` capture. See #1021 for more info.
44
"""
55

6-
from talon import Context, Module
6+
from talon import Module, app, registry
77

88
mod = Module()
9-
mod.tag(
10-
"cursorless_custom_number_small",
11-
"This tag causes Cursorless to use the global <number_small> capture",
12-
)
139

14-
ctx = Context()
15-
ctx.matches = """
16-
not tag: user.cursorless_custom_number_small
17-
"""
18-
19-
20-
@mod.capture(rule="<number_small>")
21-
def private_cursorless_number_small(m) -> int:
22-
return m.number_small
23-
24-
25-
digit_list = "zero one two three four five six seven eight nine".split()
26-
teens = "ten eleven twelve thirteen fourteen fifteen sixteen seventeen eighteen nineteen".split()
27-
tens = "twenty thirty forty fifty sixty seventy eighty ninety".split()
10+
mod.tag("cursorless_custom_number_small", "DEPRECATED!")
2811

29-
number_small_list = [*digit_list, *teens]
30-
for ten in tens:
31-
number_small_list.append(ten)
32-
number_small_list.extend(f"{ten} {digit}" for digit in digit_list[1:])
33-
number_small_map = {n: i for i, n in enumerate(number_small_list)}
3412

35-
mod.list("private_cursorless_number_small", desc="List of small numbers")
36-
# FIXME: Remove type ignore once Talon supports list types
37-
# See https://github.com/talonvoice/talon/issues/654
38-
ctx.lists["self.private_cursorless_number_small"] = number_small_map.keys() # pyright: ignore [reportArgumentType]
13+
def on_ready():
14+
if "user.cursorless_custom_number_small" in registry.tags:
15+
print(
16+
"WARNING tag: 'user.cursorless_custom_number_small' is deprecated and should not be used anymore, as Cursorless now uses community number_small"
17+
)
3918

4019

41-
@ctx.capture(
42-
"user.private_cursorless_number_small",
43-
rule="{user.private_cursorless_number_small}",
44-
)
45-
def override_private_cursorless_number_small(m) -> int:
46-
return number_small_map[m.private_cursorless_number_small]
20+
app.register("ready", on_ready)
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
languageId: typescript
2+
command:
3+
version: 7
4+
spokenForm: change pair
5+
action:
6+
name: clearAndSetSelection
7+
target:
8+
type: primitive
9+
modifiers:
10+
- type: containingScope
11+
scopeType: {type: surroundingPair, delimiter: any}
12+
usePrePhraseSnapshot: true
13+
initialState:
14+
documentContents: "[1, ']', 2]"
15+
selections:
16+
- anchor: {line: 0, character: 1}
17+
active: {line: 0, character: 1}
18+
marks: {}
19+
finalState:
20+
documentContents: ""
21+
selections:
22+
- anchor: {line: 0, character: 0}
23+
active: {line: 0, character: 0}

0 commit comments

Comments
 (0)