From 704b428d5f9d68253a280016de75eef863951f5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A8=8B=E5=BA=8F=E5=91=98=E5=B0=8F=E5=A2=A8?= <2291200076@qq.com> Date: Thu, 4 Apr 2024 15:36:06 +0800 Subject: [PATCH] =?UTF-8?q?=E6=98=AF=E5=90=A6=E5=B1=95=E7=A4=BA=E5=8F=B3?= =?UTF-8?q?=E9=94=AE=E8=8F=9C=E5=8D=95=E9=80=BB=E8=BE=91=E5=9C=A8=20VSCode?= =?UTF-8?q?=20=E6=8F=92=E4=BB=B6=E5=88=9D=E5=A7=8B=E5=8C=96=E6=97=B6?= =?UTF-8?q?=E4=B9=9F=E4=B9=9F=E5=88=A4=E6=96=AD=E4=B8=80=E6=AC=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/extension.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/extension.ts b/src/extension.ts index 66f3622..922125f 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -30,6 +30,18 @@ export function activate(context: vscode.ExtensionContext) { vscode.commands.executeCommand('setContext', '_textSelectionLength', text.length); }); + // 初始(VSCode 插件初始化)时也判断一次 (考虑上次关闭 VSCode 有选区,重新打开后 VSCode 回复选区但用户未重新切换选区的场景) + let editor = vscode.window.activeTextEditor; + if (editor) { + let document = editor.document; + let selection = editor.selection; + // 获取选中的文本 + let text = document.getText(selection); + vscode.commands.executeCommand('setContext', '_textSelectionLength', text.length); + } else { + vscode.window.showInformationMessage('editor is undefined'); + } + const commands: Array<{ command: string; convertFunction: ConvertFunction }> = [ { command: 'variable-conversion.toCamelCase', convertFunction: TextConversion.toCamelCase }, { command: 'variable-conversion.toPascalCase', convertFunction: TextConversion.toPascalCase },