1
0
Code Issues Pull Requests Packages Projects Releases Wiki Activity GitHub Gitee

仅当选中了文字后,才显示右键菜单

This commit is contained in:
zhangbk1 2024-04-03 09:58:25 +08:00
parent 35f778517e
commit 24223d0423
2 changed files with 7 additions and 0 deletions

View File

@ -93,6 +93,7 @@
"group": "1_modification@9" "group": "1_modification@9"
}, },
{ {
"when": "editorTextFocus && _textSelectionLength >= 1",
"submenu": "extension.stringConversionMenu", "submenu": "extension.stringConversionMenu",
"group": "1_modification@9" "group": "1_modification@9"
} }

View File

@ -21,6 +21,12 @@ export function activate(context: vscode.ExtensionContext) {
// vscode.window.showInformationMessage('Hello World from text-conversion!'); // 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) => { const handleEditorReplace = (convertFunction: ConvertFunction) => {
// 获取当前编辑器 // 获取当前编辑器
let editor = vscode.window.activeTextEditor; let editor = vscode.window.activeTextEditor;