Skip to content

Commit 5f7b339

Browse files
authored
Merge branch 'main' into main
2 parents 8827e84 + 85fd827 commit 5f7b339

File tree

57 files changed

+1355
-326
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+1355
-326
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: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
from talon import Context, Module, actions
2+
3+
from .cursorless_everywhere_types import (
4+
EditorEdit,
5+
EditorState,
6+
SelectionOffsets,
7+
)
8+
9+
mod = Module()
10+
11+
mod.tag(
12+
"cursorless_everywhere_talon_browser",
13+
desc="Enable RPC to browser extension when using cursorless everywhere in Talon",
14+
)
15+
16+
ctx = Context()
17+
ctx.matches = r"""
18+
tag: user.cursorless_everywhere_talon_browser
19+
"""
20+
21+
RPC_COMMAND = "talonCommand"
22+
23+
24+
@ctx.action_class("user")
25+
class Actions:
26+
def cursorless_everywhere_get_editor_state() -> EditorState:
27+
command = {
28+
"id": "getEditorState",
29+
}
30+
res = rpc_get(command)
31+
if use_fallback(res):
32+
return actions.next()
33+
return res
34+
35+
def cursorless_everywhere_set_selections(
36+
selections: list[SelectionOffsets], # pyright: ignore [reportGeneralTypeIssues]
37+
):
38+
command = {
39+
"id": "setSelections",
40+
"selections": [
41+
js_object_to_python_dict(s, ["anchor", "active"])
42+
for s in js_array_to_python_list(selections)
43+
],
44+
}
45+
res = rpc_get(command)
46+
if use_fallback(res):
47+
actions.next(selections)
48+
49+
def cursorless_everywhere_edit_text(
50+
edit: EditorEdit, # pyright: ignore [reportGeneralTypeIssues]
51+
):
52+
command = {
53+
"id": "editText",
54+
"text": edit["text"],
55+
"changes": [
56+
js_object_to_python_dict(c, ["text", "rangeOffset", "rangeLength"])
57+
for c in js_array_to_python_list(edit["changes"])
58+
],
59+
}
60+
res = rpc_get(command)
61+
if use_fallback(res):
62+
actions.next(edit)
63+
64+
65+
def rpc_get(command: dict):
66+
return actions.user.run_rpc_command_get(RPC_COMMAND, command)
67+
68+
69+
def use_fallback(result: dict) -> bool:
70+
return result.get("fallback", False)
71+
72+
73+
def js_array_to_python_list(array) -> list:
74+
result = []
75+
for i in range(array.length):
76+
result.append(array[i])
77+
return result
78+
79+
80+
def js_object_to_python_dict(object, keys: list[str]) -> dict:
81+
result = {}
82+
for key in keys:
83+
result[key] = object[key]
84+
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/get_grapheme_spoken_form_entries.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import typing
33
from collections import defaultdict
44
from typing import Iterator, Mapping
5-
from uu import Error
65

76
from talon import app, registry, scope
87

@@ -55,7 +54,7 @@ def generate_lists_from_capture(capture_name) -> Iterator[str]:
5554
try:
5655
# NB: [-1] because the last capture is the active one
5756
rule = registry.captures[capture_name][-1].rule.rule
58-
except Error:
57+
except Exception:
5958
app.notify("Error constructing spoken forms for graphemes")
6059
print(f"Error getting rule for capture {capture_name}")
6160
return
@@ -86,7 +85,7 @@ def get_id_to_talon_list(list_name: str) -> dict[str, str]:
8685
try:
8786
# NB: [-1] because the last list is the active one
8887
return typing.cast(dict[str, str], registry.lists[list_name][-1]).copy()
89-
except Error:
88+
except Exception:
9089
app.notify(f"Error getting list {list_name}")
9190
return {}
9291

cursorless-talon/src/spoken_forms.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22
"NOTE FOR USERS": "Please don't edit this json file; see https://www.cursorless.org/docs/user/customization",
33
"actions.csv": {
44
"simple_action": {
5+
"append post": "addSelectionAfter",
6+
"append pre": "addSelectionBefore",
7+
"append": "addSelection",
58
"bottom": "scrollToBottom",
6-
"break": "breakLine",
79
"break point": "toggleLineBreakpoint",
10+
"break": "breakLine",
811
"carve": "cutToClipboard",
912
"center": "scrollToCenter",
1013
"change": "clearAndSetSelection",
@@ -22,8 +25,8 @@
2225
"extract": "extractVariable",
2326
"float": "insertEmptyLineAfter",
2427
"fold": "foldRegion",
25-
"follow": "followLink",
2628
"follow split": "followLinkAside",
29+
"follow": "followLink",
2730
"give": "deselect",
2831
"highlight": "highlight",
2932
"hover": "showHover",
@@ -39,8 +42,8 @@
3942
"reference": "showReferences",
4043
"rename": "rename",
4144
"reverse": "reverseTargets",
42-
"scout": "findInDocument",
4345
"scout all": "findInWorkspace",
46+
"scout": "findInDocument",
4447
"shuffle": "randomizeTargets",
4548
"snippet make": "generateSnippet",
4649
"sort": "sortTargets",

cursorless-talon/src/spoken_forms.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ def handle_new_values(csv_name: str, values: list[SpokenFormEntry]):
160160
"private.switchStatementSubject",
161161
"textFragment",
162162
"disqualifyDelimiter",
163+
"pairDelimiter",
163164
],
164165
default_list_name="scope_type",
165166
),
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
languageId: plaintext
2+
command:
3+
version: 7
4+
spokenForm: append post whale
5+
action:
6+
name: addSelectionAfter
7+
target:
8+
type: primitive
9+
mark: {type: decoratedSymbol, symbolColor: default, character: w}
10+
usePrePhraseSnapshot: true
11+
initialState:
12+
documentContents: hello world
13+
selections:
14+
- anchor: {line: 0, character: 0}
15+
active: {line: 0, character: 0}
16+
marks:
17+
default.w:
18+
start: {line: 0, character: 6}
19+
end: {line: 0, character: 11}
20+
finalState:
21+
documentContents: hello world
22+
selections:
23+
- anchor: {line: 0, character: 0}
24+
active: {line: 0, character: 0}
25+
- anchor: {line: 0, character: 11}
26+
active: {line: 0, character: 11}
27+
thatMark:
28+
- type: UntypedTarget
29+
contentRange:
30+
start: {line: 0, character: 6}
31+
end: {line: 0, character: 11}
32+
isReversed: false
33+
hasExplicitRange: false
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
languageId: plaintext
2+
command:
3+
version: 7
4+
spokenForm: append pre whale
5+
action:
6+
name: addSelectionBefore
7+
target:
8+
type: primitive
9+
mark: {type: decoratedSymbol, symbolColor: default, character: w}
10+
usePrePhraseSnapshot: true
11+
initialState:
12+
documentContents: hello world
13+
selections:
14+
- anchor: {line: 0, character: 0}
15+
active: {line: 0, character: 0}
16+
marks:
17+
default.w:
18+
start: {line: 0, character: 6}
19+
end: {line: 0, character: 11}
20+
finalState:
21+
documentContents: hello world
22+
selections:
23+
- anchor: {line: 0, character: 0}
24+
active: {line: 0, character: 0}
25+
- anchor: {line: 0, character: 6}
26+
active: {line: 0, character: 6}
27+
thatMark:
28+
- type: UntypedTarget
29+
contentRange:
30+
start: {line: 0, character: 6}
31+
end: {line: 0, character: 11}
32+
isReversed: false
33+
hasExplicitRange: false
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
languageId: plaintext
2+
command:
3+
version: 7
4+
spokenForm: append whale
5+
action:
6+
name: addSelection
7+
target:
8+
type: primitive
9+
mark: {type: decoratedSymbol, symbolColor: default, character: w}
10+
usePrePhraseSnapshot: true
11+
initialState:
12+
documentContents: hello world
13+
selections:
14+
- anchor: {line: 0, character: 0}
15+
active: {line: 0, character: 0}
16+
marks:
17+
default.w:
18+
start: {line: 0, character: 6}
19+
end: {line: 0, character: 11}
20+
finalState:
21+
documentContents: hello world
22+
selections:
23+
- anchor: {line: 0, character: 0}
24+
active: {line: 0, character: 0}
25+
- anchor: {line: 0, character: 6}
26+
active: {line: 0, character: 11}
27+
thatMark:
28+
- type: UntypedTarget
29+
contentRange:
30+
start: {line: 0, character: 6}
31+
end: {line: 0, character: 11}
32+
isReversed: false
33+
hasExplicitRange: false

0 commit comments

Comments
 (0)