-
-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'cursorless-dev:main' into cursorless-jetbrains
- Loading branch information
Showing
166 changed files
with
3,614 additions
and
1,465 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
tags: [enhancement] | ||
pullRequest: 2683 | ||
--- | ||
|
||
At long last, collection items have been migrated to our next generation scope framework! This means, within a list of items, you can now use relative navigation (`previous item`), absolute navigation via ordinals (`fifth item`), multiple selection (`two items`, optionally preceded with `previous` or `next`), and lastly, requesting multiple items to be individually selected via `every` (`every two items`)! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 99 additions & 0 deletions
99
cursorless-everywhere-talon/cursorless_everywhere_talon_browser.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
from talon import Context, Module, actions | ||
|
||
from .cursorless_everywhere_types import ( | ||
EditorEdit, | ||
EditorState, | ||
RangeOffsets, | ||
SelectionOffsets, | ||
) | ||
|
||
mod = Module() | ||
|
||
mod.tag( | ||
"cursorless_everywhere_talon_browser", | ||
desc="Enable RPC to browser extension when using cursorless everywhere in Talon", | ||
) | ||
|
||
ctx = Context() | ||
ctx.matches = r""" | ||
tag: user.cursorless_everywhere_talon_browser | ||
""" | ||
|
||
RPC_COMMAND = "talonCommand" | ||
|
||
|
||
@ctx.action_class("user") | ||
class Actions: | ||
def cursorless_everywhere_get_editor_state() -> EditorState: | ||
command = { | ||
"id": "getEditorState", | ||
} | ||
res = rpc_get(command) | ||
if use_fallback(res): | ||
return actions.next() | ||
return res | ||
|
||
def cursorless_everywhere_set_selections( | ||
selections: list[SelectionOffsets], # pyright: ignore [reportGeneralTypeIssues] | ||
): | ||
command = { | ||
"id": "setSelections", | ||
"selections": [ | ||
js_object_to_python_dict(s, ["anchor", "active"]) | ||
for s in js_array_to_python_list(selections) | ||
], | ||
} | ||
res = rpc_get(command) | ||
if use_fallback(res): | ||
actions.next(selections) | ||
|
||
def cursorless_everywhere_edit_text( | ||
edit: EditorEdit, # pyright: ignore [reportGeneralTypeIssues] | ||
): | ||
command = { | ||
"id": "editText", | ||
"text": edit["text"], | ||
"changes": [ | ||
js_object_to_python_dict(c, ["text", "rangeOffset", "rangeLength"]) | ||
for c in js_array_to_python_list(edit["changes"]) | ||
], | ||
} | ||
res = rpc_get(command) | ||
if use_fallback(res): | ||
actions.next(edit) | ||
|
||
def cursorless_everywhere_flash_ranges( | ||
ranges: list[RangeOffsets], # pyright: ignore [reportGeneralTypeIssues] | ||
): | ||
command = { | ||
"id": "flashRanges", | ||
"ranges": [ | ||
js_object_to_python_dict(r, ["start", "end"]) | ||
for r in js_array_to_python_list(ranges) | ||
], | ||
} | ||
res = rpc_get(command) | ||
if use_fallback(res): | ||
actions.next(ranges) | ||
|
||
|
||
def rpc_get(command: dict): | ||
return actions.user.run_rpc_command_get(RPC_COMMAND, command) | ||
|
||
|
||
def use_fallback(result: dict) -> bool: | ||
return result.get("fallback", False) | ||
|
||
|
||
def js_array_to_python_list(array) -> list: | ||
result = [] | ||
for i in range(array.length): | ||
result.append(array[i]) | ||
return result | ||
|
||
|
||
def js_object_to_python_dict(object, keys: list[str]) -> dict: | ||
result = {} | ||
for key in keys: | ||
result[key] = object[key] | ||
return result |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Please file pull requests to the cursorless-talon subdirectory in the https://github.com/cursorless-dev/cursorless repo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
from talon import app, registry | ||
|
||
required_captures = [ | ||
"number_small", | ||
"user.any_alphanumeric_key", | ||
"user.formatters", | ||
"user.ordinals_small", | ||
] | ||
|
||
required_actions = [ | ||
"user.homophones_get", | ||
"user.reformat_text", | ||
] | ||
|
||
|
||
def on_ready(): | ||
missing_captures = [ | ||
capture for capture in required_captures if capture not in registry.captures | ||
] | ||
missing_actions = [ | ||
action for action in required_actions if action not in registry.actions | ||
] | ||
errors = [] | ||
if missing_captures: | ||
errors.append(f"Missing captures: {', '.join(missing_captures)}") | ||
if missing_actions: | ||
errors.append(f"Missing actions: {', '.join(missing_actions)}") | ||
if errors: | ||
print("Cursorless community requirements:") | ||
print("\n".join(errors)) | ||
app.notify( | ||
"Cursorless: Please install the community repository", | ||
body="https://github.com/talonhub/community", | ||
) | ||
|
||
|
||
app.register("ready", on_ready) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.