From 24223d04230ab53ac7ff408ef0136b527851e267 Mon Sep 17 00:00:00 2001 From: zhangbk1 Date: Wed, 3 Apr 2024 09:58:25 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=85=E5=BD=93=E9=80=89=E4=B8=AD=E4=BA=86?= =?UTF-8?q?=E6=96=87=E5=AD=97=E5=90=8E=EF=BC=8C=E6=89=8D=E6=98=BE=E7=A4=BA?= =?UTF-8?q?=E5=8F=B3=E9=94=AE=E8=8F=9C=E5=8D=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 1 + src/extension.ts | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/package.json b/package.json index 83a7ff1..0d6315f 100644 --- a/package.json +++ b/package.json @@ -93,6 +93,7 @@ "group": "1_modification@9" }, { + "when": "editorTextFocus && _textSelectionLength >= 1", "submenu": "extension.stringConversionMenu", "group": "1_modification@9" } diff --git a/src/extension.ts b/src/extension.ts index 50084c3..9ebb3d3 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -21,6 +21,12 @@ export function activate(context: vscode.ExtensionContext) { // vscode.window.showInformationMessage('Hello World from text-conversion!'); // }); + // 用于判断是否展示右键菜单 + vscode.window.onDidChangeTextEditorSelection(event => { + const text = event.textEditor.document.getText(event.selections[0]); + vscode.commands.executeCommand('setContext', '_textSelectionLength', text.length); + }); + const handleEditorReplace = (convertFunction: ConvertFunction) => { // 获取当前编辑器 let editor = vscode.window.activeTextEditor;