diff --git a/src/actions/actions.py b/src/actions/actions.py index 34ea9170..c4654b3b 100644 --- a/src/actions/actions.py +++ b/src/actions/actions.py @@ -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() diff --git a/src/actions/insert.py b/src/actions/insert.py new file mode 100644 index 00000000..8bbbc1e9 --- /dev/null +++ b/src/actions/insert.py @@ -0,0 +1,26 @@ +from talon import Module + +mod = Module() + +mod.list("cursorless_insert_action", desc="Cursorless insert action") + + +@mod.capture(rule="count [from ]") +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=(" |" "") +) +def cursorless_insert_value(m) -> str: + return m[0] diff --git a/src/command.py b/src/command.py index 04db0ae3..d31e38c2 100644 --- a/src/command.py +++ b/src/command.py @@ -1,5 +1,6 @@ from talon import actions, Module, speech_system from typing import Any, List +from .primitive_target import STRICT_HERE mod = Module() @@ -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, diff --git a/src/cursorless.talon b/src/cursorless.talon index 146b5d50..45ec1159 100644 --- a/src/cursorless.talon +++ b/src/cursorless.talon @@ -13,6 +13,9 @@ app: vscode {user.cursorless_reformat_action} at : user.cursorless_reformat(cursorless_target, formatters) +{user.cursorless_insert_action} : + user.cursorless_no_target_command("insert", cursorless_insert_value) + {user.cursorless_wrap_action} : user.cursorless_single_target_command_with_arg_list(cursorless_wrap_action, cursorless_target, cursorless_wrapper)