-
-
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.
Add
cursorless_create_destination
action to talon api (#2402)
This came up during a pairing session. I wanted to do something like: ```talon transform <user.cursorless_target>: old = user.cursorless_get_text(cursorless_target, 1) new = some_transformation(old) destination = user.cursorless_create_destination(cursorless_target) user.cursorless_insert(destination, new) ``` Notice I can't use our existing `user.cursorless_insert` out of the box because it expects a destination, so we need a way to make a destination from a target ## Checklist - [-] I have added [tests](https://www.cursorless.org/docs/contributing/test-case-recorder/) - [x] 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
- Loading branch information
Showing
5 changed files
with
77 additions
and
1 deletion.
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, talon] | ||
pullRequest: 2402 | ||
--- | ||
|
||
- Add `user.cursorless_create_destination` to the public API. See the [Talon-side api docs](../docs/user/customization.md#cursorless-public-api) and the example code in the [How do I run a custom Python transformation on a target?](../docs/user/how-to.md#how-do-i-run-a-custom-python-transformation-on-a-target) section for more information. |
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,22 @@ | ||
from talon import Module | ||
|
||
from .targets.target_types import ( | ||
CursorlessDestination, | ||
InsertionMode, | ||
ListTarget, | ||
PrimitiveDestination, | ||
PrimitiveTarget, | ||
RangeTarget, | ||
) | ||
|
||
mod = Module() | ||
|
||
|
||
@mod.action_class | ||
class Actions: | ||
def cursorless_create_destination( | ||
target: ListTarget | RangeTarget | PrimitiveTarget, # pyright: ignore [reportGeneralTypeIssues] | ||
insertion_mode: InsertionMode = "to", | ||
) -> CursorlessDestination: | ||
"""Cursorless: Create destination from target""" | ||
return PrimitiveDestination(insertion_mode, target) |
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