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;