diff --git a/src/command.py b/src/command.py index 0e061c2c..d49eff6d 100644 --- a/src/command.py +++ b/src/command.py @@ -61,13 +61,13 @@ def cursorless_single_target_command_get( arg3: Any = NotSet, ): """Execute single-target cursorless command and return result""" - args = list(filter(lambda x: x is not NotSet, [arg1, arg2, arg3])) return actions.user.vscode_get( "cursorless.command", - get_spoken_form(), - action, - [target], - *args, + construct_cursorless_command_argument( + action=action, + targets=[target], + args=[x for x in [arg1, arg2, arg3] if x is not NotSet], + ), ) def cursorless_multiple_target_command( @@ -78,15 +78,33 @@ def cursorless_multiple_target_command( arg3: any = NotSet, ): """Execute multi-target cursorless command""" - args = list(filter(lambda x: x is not NotSet, [arg1, arg2, arg3])) actions.user.vscode_with_plugin_and_wait( "cursorless.command", - get_spoken_form(), - action, - targets, - *args, + construct_cursorless_command_argument( + action=action, + targets=targets, + args=[x for x in [arg1, arg2, arg3] if x is not NotSet], + ), ) +def construct_cursorless_command_argument( + action: str, targets: list[dict], args: list[any] +): + try: + use_pre_phrase_snapshot = actions.user.did_emit_pre_phrase_signal() + except KeyError: + use_pre_phrase_snapshot = False + + return { + "version": 1, + "spokenForm": get_spoken_form(), + "action": action, + "targets": targets, + "extraArgs": args, + "usePrePhraseSnapshot": use_pre_phrase_snapshot, + } + + def get_spoken_form(): return " ".join(last_phrase["phrase"])