From 95b456faf67e0611c694a53f8e8bc84f3215b24f Mon Sep 17 00:00:00 2001 From: Pokey Rule <755842+pokey@users.noreply.github.com> Date: Mon, 3 Jun 2024 12:58:45 +0100 Subject: [PATCH] Experiments with cursorless snippet sources --- apps/vscode/vscode.py | 10 ++++++++++ apps/vscode/vscode.talon | 8 ++++++++ core/snippets/snippets/nullCheck.snippet | 22 ++++++++++++++++++++++ 3 files changed, 40 insertions(+) create mode 100644 core/snippets/snippets/nullCheck.snippet diff --git a/apps/vscode/vscode.py b/apps/vscode/vscode.py index b65b27a186..0dc5f6f875 100644 --- a/apps/vscode/vscode.py +++ b/apps/vscode/vscode.py @@ -2,6 +2,7 @@ import re from os.path import expanduser from pathlib import Path +from typing import Any from talon import Context, Module, actions, app, clip @@ -283,6 +284,15 @@ def vscode_add_missing_imports(): {"kind": "source.addMissingImports", "apply": "first"}, ) + def insert_snippet_with_cursorless_target( + name: str, variable_name: str, target: Any + ): + """Insert snippet with cursorless target """ + actions.user.insert_snippet_by_name( + name, + {variable_name: actions.user.cursorless_get_text(target)}, + ) + @mac_ctx.action_class("user") class MacUserActions: diff --git a/apps/vscode/vscode.talon b/apps/vscode/vscode.talon index d734fc881a..1123f13268 100644 --- a/apps/vscode/vscode.talon +++ b/apps/vscode/vscode.talon @@ -579,6 +579,14 @@ replace here: user.replace("") key(cmd-alt-l) +replace : + user.cursorless_command("setSelection", cursorless_target) + user.replace("") + key(cmd-alt-l) + +none check : + user.insert_snippet_with_cursorless_target("nullCheck", "1", cursorless_target) + full screen: user.vscode("workbench.action.toggleFullScreen") curse undo: user.vscode("cursorUndo") diff --git a/core/snippets/snippets/nullCheck.snippet b/core/snippets/snippets/nullCheck.snippet new file mode 100644 index 0000000000..bf61e0597e --- /dev/null +++ b/core/snippets/snippets/nullCheck.snippet @@ -0,0 +1,22 @@ +name: nullCheck +phrase: none check +insertionScope: statement + +$1.wrapperPhrase: none check cond +$1.wrapperScope: statement +$0.wrapperPhrase: none check +$0.wrapperScope: statement +--- + +language: javascript +- +if ($1 != null) { + $0 +} +--- + +language: python +- +if $1 is not None: + $0 +---