Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Public get text action #2069

Merged
merged 29 commits into from
Dec 19, 2023
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
4d1b83d
Made public get text action
AndreasArvidsson Nov 29, 2023
16e26f5
Added spoken form tests
AndreasArvidsson Dec 1, 2023
7436c88
clean up
AndreasArvidsson Dec 1, 2023
84baff0
Split get text action into two separate actions
AndreasArvidsson Dec 2, 2023
d166bd4
[pre-commit.ci lite] apply automatic fixes
pre-commit-ci-lite[bot] Dec 2, 2023
43e5f05
Remove unused import
AndreasArvidsson Dec 2, 2023
48c73a6
Merge branch 'get_text_action' of github.com:cursorless-dev/cursorles…
AndreasArvidsson Dec 2, 2023
8da2961
Update docs/user/customization.md
AndreasArvidsson Dec 4, 2023
24a4612
invert boolean argument
AndreasArvidsson Dec 5, 2023
46d2f48
Fixed
AndreasArvidsson Dec 5, 2023
ab8b436
Update
AndreasArvidsson Dec 5, 2023
a690090
Flip boolean
AndreasArvidsson Dec 5, 2023
b717b32
Update fixtures
AndreasArvidsson Dec 5, 2023
99d7964
Update phrasing
AndreasArvidsson Dec 5, 2023
a4bb31f
work work
AndreasArvidsson Dec 7, 2023
216b7f9
[pre-commit.ci lite] apply automatic fixes
pre-commit-ci-lite[bot] Dec 7, 2023
c518b9b
Merge branch 'main' into get_text_action
pokey Dec 18, 2023
4556f10
Tweaks
pokey Dec 18, 2023
5d3d7f2
fixes
pokey Dec 18, 2023
1953bb1
fix
pokey Dec 18, 2023
10252a4
Fix talon tests
pokey Dec 18, 2023
3887fbb
docs
pokey Dec 18, 2023
cf8f1b4
fixes
pokey Dec 19, 2023
e26c816
Update docs
pokey Dec 19, 2023
2f7985c
Update doc string#
pokey Dec 19, 2023
258570b
Fixes
pokey Dec 19, 2023
fcdf675
Merge branch 'main' into get_text_action
pokey Dec 19, 2023
4900e1a
Merge branch 'main' into get_text_action
pokey Dec 19, 2023
c7d20de
fix
pokey Dec 19, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions cursorless-talon-dev/src/cursorless_test.talon
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,20 @@ test api command <user.cursorless_target>:
user.cursorless_command("setSelection", cursorless_target)
test api command bring <user.cursorless_target>:
user.cursorless_command("replaceWithTarget", cursorless_target)
test api get text <user.cursorless_target>:
user.cursorless_get_text(cursorless_target)
test api get text list on <user.cursorless_target>:
pokey marked this conversation as resolved.
Show resolved Hide resolved
user.cursorless_get_text_list(cursorless_target)
test api get text hide decorations <user.cursorless_target>:
user.cursorless_get_text(cursorless_target, 1)
pokey marked this conversation as resolved.
Show resolved Hide resolved
test api get text hide decorations list on <user.cursorless_target>:
user.cursorless_get_text_list(cursorless_target, 1)

test api insert <user.word> <user.cursorless_destination>:
user.cursorless_insert(cursorless_destination, word)
test api insert <user.word> and <user.word> <user.cursorless_destination>:
user.cursorless_insert(cursorless_destination, word_list)

test api insert snippet:
user.cursorless_insert_snippet("Hello, $foo! My name is $bar!")
test api insert snippet <user.cursorless_destination> :
Expand Down
29 changes: 28 additions & 1 deletion cursorless-talon/src/actions/get_text.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,36 @@
from typing import Optional

from talon import actions
from talon import Module, actions

from ..targets.target_types import CursorlessTarget

mod = Module()


@mod.action_class
class Actions:
def cursorless_get_text(
target: CursorlessTarget,
hide_decorations: bool = False,
AndreasArvidsson marked this conversation as resolved.
Show resolved Hide resolved
) -> str:
"""Get target text. If silent, don't show decorations"""
return cursorless_get_text_action(
target,
show_decorations=not hide_decorations,
ensure_single_target=True,
)[0]

def cursorless_get_text_list(
target: CursorlessTarget,
hide_decorations: bool = False,
) -> list[str]:
"""Get texts for multiple targets. If silent, don't show decorations"""
return cursorless_get_text_action(
target,
show_decorations=not hide_decorations,
ensure_single_target=False,
)


def cursorless_get_text_action(
target: CursorlessTarget,
Expand Down
4 changes: 4 additions & 0 deletions docs/user/customization.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ Cursorless exposes a couple talon actions and captures that you can use to defin
- `user.cursorless_ide_command(command_id: str, target: cursorless_target)`:
Performs a built-in IDE command on the given target
eg: `user.cursorless_ide_command("editor.action.addCommentLine", cursorless_target)`
- `user.cursorless_get_text(target: CursorlessTarget, silent: bool = False) -> str`
Get text from target. If `silent` is `true`, will not show decorations.
- `user.cursorless_get_text_list(target: CursorlessTarget, silent: bool = False) -> list[str]`
Get texts from multiple targets. If `silent` is `true`, will not show decorations.
- `user.cursorless_insert(destination: CursorlessDestination, text: Union[str, List[str]])`:
Insert text at destination.
eg: `user.cursorless_insert(cursorless_destination, "hello")`
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import {
ActionDescriptor,
GetTextActionOptions,
PartialPrimitiveTargetDescriptor,
} from "@cursorless/common";
import { spokenFormTest } from "./spokenFormTest";
import { multiActionSpokenFormTest, spokenFormTest } from "./spokenFormTest";

// See cursorless-talon-dev/src/cursorless_test.talon
const setSelectionAction: ActionDescriptor = {
Expand Down Expand Up @@ -97,6 +98,14 @@ const parseTreeAction: ActionDescriptor = {
target: decoratedPrimitiveTarget("a"),
};

function getTextAction(options: GetTextActionOptions): ActionDescriptor {
return {
name: "getText",
options,
target: decoratedPrimitiveTarget("a"),
};
}

/**
* These test our Talon api using dummy spoken forms defined in
* cursorless-talon-dev/src/cursorless_test.talon
Expand All @@ -121,6 +130,26 @@ export const talonApiFixture = [
wrapWithSnippetByNameAction,
),
spokenFormTest("parse tree air", parseTreeAction),
multiActionSpokenFormTest(
pokey marked this conversation as resolved.
Show resolved Hide resolved
"test api get text air",
[getTextAction({ showDecorations: true, ensureSingleTarget: true })],
["apple"],
),
multiActionSpokenFormTest(
"test api get text list on air",
[getTextAction({ showDecorations: true, ensureSingleTarget: false })],
["apple"],
),
multiActionSpokenFormTest(
"test api get text hide decorations air",
[getTextAction({ showDecorations: false, ensureSingleTarget: true })],
["apple"],
),
multiActionSpokenFormTest(
"test api get text hide decorations list on air",
[getTextAction({ showDecorations: false, ensureSingleTarget: false })],
["apple"],
),
];

function decoratedPrimitiveTarget(
Expand Down