Skip to content

Commit

Permalink
Add rewrap action (#120)
Browse files Browse the repository at this point in the history
* Initial working version

* Some documentation
  • Loading branch information
pokey committed Dec 13, 2021
1 parent 774196f commit 55189b1
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/actions/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def run_makeshift_action(action: str, targets: dict):
"simple_action": simple_actions,
"swap_action": {"swap": "swapTargets"},
"move_bring_action": {"bring": "replaceWithTarget", "move": "moveToTarget"},
"wrap_action": {"wrap": "wrapWithPairedDelimiter"},
"wrap_action": {"wrap": "wrapWithPairedDelimiter", "repack": "rewrap"},
"reformat_action": {"format": "applyFormatter"},
}

Expand Down
22 changes: 18 additions & 4 deletions src/actions/wrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,22 +39,36 @@ def cursorless_wrapper(m) -> Union[list[str], str]:
m.cursorless_wrapper_paired_delimiter
]
return {
"action": "wrapWithPairedDelimiter",
"type": "pairedDelimiter",
"extra_args": [paired_delimiter_info.left, paired_delimiter_info.right],
}
except AttributeError:
return {
"action": "wrapWithSnippet",
"type": "snippet",
"extra_args": [m.cursorless_wrapper_snippet],
}


# Maps from (action_type, wrapper_type) to action name
action_map = {
("wrapWithPairedDelimiter", "pairedDelimiter"): "wrapWithPairedDelimiter",
# This is awkward because we used an action name which was to verbose previously
("wrapWithPairedDelimiter", "snippet"): "wrapWithSnippet",
("rewrap", "pairedDelimiter"): "rewrapWithPairedDelimiter",
# Not yet supported
("rewrap", "snippet"): "rewrapWithSnippet",
}


@mod.action_class
class Actions:
def cursorless_wrap(cursorless_wrapper: dict, targets: dict):
def cursorless_wrap(action_type: str, targets: dict, cursorless_wrapper: dict):
"""Perform cursorless wrap action"""
wrapper_type = cursorless_wrapper["type"]
action = action_map[(action_type, wrapper_type)]

actions.user.cursorless_single_target_command_with_arg_list(
cursorless_wrapper["action"], targets, cursorless_wrapper["extra_args"]
action, targets, cursorless_wrapper["extra_args"]
)


Expand Down
2 changes: 1 addition & 1 deletion src/cursorless.talon
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ app: vscode
user.cursorless_reformat(cursorless_target, formatters)

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

cursorless help: user.cursorless_cheat_sheet_toggle()
cursorless instructions: user.cursorless_open_instructions()

0 comments on commit 55189b1

Please sign in to comment.