gpt4 book ai didi

javascript - 我可以为装饰文本添加鼠标单击回调吗?

转载 作者:行者123 更新时间:2023-12-02 22:40:41 25 4
gpt4 key购买 nike

我对文本部分应用了装饰(与正则表达式匹配),它可以选择指定 hoverMessage 我想知道是否有一种方法可以指定对此元素的鼠标单击。我想根据用户单击的装饰文本执行一些函数。

最佳答案

我找不到任何鼠标点击的解决方案。 other SO中提到过问题是公开鼠标事件不太可能添加到 API :(

我能做的是:

  • 添加贡献点:
    • 命令
    • 菜单
      • 编辑器/上下文
      • 命令面板
  • 在js中注册命令并从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 中,我注册一个文本编辑器命令并使用 textEditorselectiondocument.

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);

关于javascript - 我可以为装饰文本添加鼠标单击回调吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58598797/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com