【发布时间】:2019-10-28 21:44:12
【问题描述】:
我有一个装饰应用于文本部分(与正则表达式匹配)它可以选择指定hoverMessage 我想知道是否有一种方法可以指定鼠标点击这个元素。我想根据用户点击的装饰文本执行一些功能。
【问题讨论】:
标签: javascript visual-studio-code vscode-extensions
我有一个装饰应用于文本部分(与正则表达式匹配)它可以选择指定hoverMessage 我想知道是否有一种方法可以指定鼠标点击这个元素。我想根据用户点击的装饰文本执行一些功能。
【问题讨论】:
标签: javascript visual-studio-code vscode-extensions
我找不到鼠标点击的任何解决方案。 other SO 问题中提到公开鼠标事件不太可能添加到 API :(
我能做的是:
textEditor获取位置
在package.json 中,我正在设置我的命令,因此当打开的文件是.log 文件时,它仅在提供title 的情况下显示在上下文菜单中。
"contributes": {
"commands": [
{
"command": "gd.my-ext.myCommand",
"title": "My Command"
}
],
"menus": {
"commandPalette": [
{
"command": "gd.me-ext.myCommand",
"when": "false"
}
],
"editor/context": [
{
"command": "gd.me-ext.myCommand",
"group": "navigation",
"when": "resourceExtname == .log"
},
]
},
然后在extension.ts 中注册一个文本编辑器命令并使用textEditor 的selection 和document。
const disposable = vscode.commands.registerTextEditorCommand(
'gd.me-ext.myCommand',
(textEditor, edit, ...rest): void => {
const { selection, document } = textEditor;
console.log(selection.start.line);
const line: vscode.TextLine = document.lineAt(selection.start.line);
// The selection will tell me where the cursor is and I can find a line
// in which I can use the regex I've used to apply decoration and compare if it was selection I wanted :)
}
);
context.subscriptions.push(disposable);
【讨论】: