|
1 | 1 | from talon import Module, actions, app |
2 | 2 |
|
3 | 3 | from ..csv_overrides import init_csv_and_watch_changes |
4 | | -from ..primitive_target import create_implicit_target |
| 4 | +from ..targets.target_types import CursorlessTarget, ImplicitDestination |
5 | 5 | from .actions_callback import callback_action_defaults, callback_action_map |
6 | 6 | from .actions_simple import ( |
7 | 7 | no_wait_actions, |
8 | 8 | no_wait_actions_post_sleep, |
9 | | - positional_action_defaults, |
10 | 9 | simple_action_defaults, |
11 | 10 | ) |
| 11 | +from .bring_move import BringMoveTargets |
| 12 | +from .execute_command import cursorless_execute_command_action |
12 | 13 |
|
13 | 14 | mod = Module() |
14 | 15 |
|
@@ -39,55 +40,53 @@ def cursorless_action_or_ide_command(m) -> dict: |
39 | 40 |
|
40 | 41 | @mod.action_class |
41 | 42 | class Actions: |
42 | | - def cursorless_command(action_id: str, target: dict): |
| 43 | + def cursorless_command(action_name: str, target: CursorlessTarget): |
43 | 44 | """Perform cursorless command on target""" |
44 | | - if action_id in callback_action_map: |
45 | | - return callback_action_map[action_id](target) |
46 | | - elif action_id in no_wait_actions: |
47 | | - actions.user.cursorless_single_target_command_no_wait(action_id, target) |
48 | | - if action_id in no_wait_actions_post_sleep: |
49 | | - actions.sleep(no_wait_actions_post_sleep[action_id]) |
50 | | - elif action_id in ["replaceWithTarget", "moveToTarget"]: |
51 | | - actions.user.cursorless_multiple_target_command( |
52 | | - action_id, [target, create_implicit_target()] |
| 45 | + if action_name in callback_action_map: |
| 46 | + callback_action_map[action_name](target) |
| 47 | + elif action_name in ["replaceWithTarget", "moveToTarget"]: |
| 48 | + actions.user.cursorless_bring_move( |
| 49 | + action_name, BringMoveTargets(target, ImplicitDestination()) |
53 | 50 | ) |
| 51 | + elif action_name in no_wait_actions: |
| 52 | + action = {"name": action_name, "target": target} |
| 53 | + actions.user.private_cursorless_command_no_wait(action) |
| 54 | + if action_name in no_wait_actions_post_sleep: |
| 55 | + actions.sleep(no_wait_actions_post_sleep[action_name]) |
54 | 56 | else: |
55 | | - return actions.user.cursorless_single_target_command(action_id, target) |
| 57 | + action = {"name": action_name, "target": target} |
| 58 | + actions.user.private_cursorless_command_and_wait(action) |
56 | 59 |
|
57 | | - def cursorless_vscode_command(command_id: str, target: dict): |
| 60 | + def cursorless_vscode_command(command_id: str, target: CursorlessTarget): |
58 | 61 | """ |
59 | 62 | Perform vscode command on cursorless target |
60 | 63 |
|
61 | 64 | Deprecated: prefer `cursorless_ide_command` |
62 | 65 | """ |
63 | 66 | return actions.user.cursorless_ide_command(command_id, target) |
64 | 67 |
|
65 | | - def cursorless_ide_command(command_id: str, target: dict): |
| 68 | + def cursorless_ide_command(command_id: str, target: CursorlessTarget): |
66 | 69 | """Perform ide command on cursorless target""" |
67 | | - return ide_command(command_id, target) |
| 70 | + return cursorless_execute_command_action(command_id, target) |
68 | 71 |
|
69 | | - def cursorless_action_or_ide_command(instruction: dict, target: dict): |
| 72 | + def private_cursorless_action_or_ide_command( |
| 73 | + instruction: dict, target: CursorlessTarget |
| 74 | + ): |
70 | 75 | """Perform cursorless action or ide command on target (internal use only)""" |
71 | 76 | type = instruction["type"] |
72 | 77 | value = instruction["value"] |
73 | 78 | if type == "cursorless_action": |
74 | | - return actions.user.cursorless_command(value, target) |
| 79 | + actions.user.cursorless_command(value, target) |
75 | 80 | elif type == "ide_command": |
76 | | - return actions.user.cursorless_ide_command(value, target) |
77 | | - |
78 | | - |
79 | | -def ide_command(command_id: str, target: dict, command_options: dict = {}): |
80 | | - return actions.user.cursorless_single_target_command( |
81 | | - "executeCommand", target, command_id, command_options |
82 | | - ) |
| 81 | + actions.user.cursorless_ide_command(value, target) |
83 | 82 |
|
84 | 83 |
|
85 | 84 | default_values = { |
86 | 85 | "simple_action": simple_action_defaults, |
87 | | - "positional_action": positional_action_defaults, |
88 | 86 | "callback_action": callback_action_defaults, |
| 87 | + "paste_action": {"paste": "pasteFromClipboard"}, |
| 88 | + "bring_move_action": {"bring": "replaceWithTarget", "move": "moveToTarget"}, |
89 | 89 | "swap_action": {"swap": "swapTargets"}, |
90 | | - "move_bring_action": {"bring": "replaceWithTarget", "move": "moveToTarget"}, |
91 | 90 | "wrap_action": {"wrap": "wrapWithPairedDelimiter", "repack": "rewrap"}, |
92 | 91 | "insert_snippet_action": {"snippet": "insertSnippet"}, |
93 | 92 | "reformat_action": {"format": "applyFormatter"}, |
|
0 commit comments