Skip to content

Added action insert #59

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

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions src/actions/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ def run_makeshift_action(action: str, targets: dict):
"move_bring_action": {"bring": "replaceWithTarget", "move": "moveToTarget"},
"wrap_action": {"wrap": "wrapWithPairedDelimiter"},
"reformat_action": {"format": "applyFormatter"},
"insert_action": {"insert": "insert"},
}

ACTION_LIST_NAMES = default_values.keys()
Expand Down
26 changes: 26 additions & 0 deletions src/actions/insert.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from talon import Module

mod = Module()

mod.list("cursorless_insert_action", desc="Cursorless insert action")


@mod.capture(rule="count [from <number_small>]")
def cursorless_range_generator(m) -> str:
try:
start = m.number_small
except AttributeError:
start = 0
return {"type": "range", "start": start}


@mod.capture(rule="{user.cursorless_paired_delimiter}")
def cursorless_pair_generator(m) -> str:
return {"type": "pair", "pair": m.cursorless_paired_delimiter}


@mod.capture(
rule=("<user.cursorless_range_generator> |" "<user.cursorless_pair_generator>")
)
def cursorless_insert_value(m) -> str:
return m[0]
12 changes: 12 additions & 0 deletions src/command.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from talon import actions, Module, speech_system
from typing import Any, List
from .primitive_target import STRICT_HERE

mod = Module()

Expand All @@ -21,6 +22,17 @@ def __repr__(self):

@mod.action_class
class Actions:
def cursorless_no_target_command(
action: str,
arg1: Any = NotSet,
arg2: Any = NotSet,
arg3: Any = NotSet,
):
"""Execute no-target cursorless command"""
actions.user.cursorless_single_target_command(
action, STRICT_HERE, arg1, arg2, arg3
)

def cursorless_single_target_command(
action: str,
target: dict,
Expand Down
3 changes: 3 additions & 0 deletions src/cursorless.talon
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ app: vscode
{user.cursorless_reformat_action} <user.formatters> at <user.cursorless_target>:
user.cursorless_reformat(cursorless_target, formatters)

{user.cursorless_insert_action} <user.cursorless_insert_value>:
user.cursorless_no_target_command("insert", cursorless_insert_value)

<user.cursorless_wrapper> {user.cursorless_wrap_action} <user.cursorless_target>:
user.cursorless_single_target_command_with_arg_list(cursorless_wrap_action, cursorless_target, cursorless_wrapper)

Expand Down