右键单击任何 TreeItem 时如何解析它的数据?
我目前正在开发一个扩展,但在实现右键单击 TreeView 中的元素(即 HomeItem 元素)的命令时遇到一些问题。
我已经实现了命令,只需单击一个元素并显示它的位置,如下所示:
in home.ts (for treeView):
this.command = {
title: "Reveal Method",
command: "extension-home.click",
arguments: [line,character]
};
in extension.ts:
let clickEvent = vscode.commands.registerCommand('extension-home.click', (line: number, character: number) => {
lineA = line;
characterA = character;
isParent = false;
// execute vscode commandto jump to location at (line,character)
const functionPosition = new vscode.Position(line,character);
vscode.window.activeTextEditor!.selections = [new vscode.Selection(functionPosition, functionPosition)];
vscode.commands.executeCommand("workbench.action.focusActiveEditorGroup");
});
现在,我获得了一些在右键单击并从上下文列表中选择时执行命令的功能,这样:
let highlightEvent = vscode.commands.registerCommand('extension-home.rightClick', () => {
if (isParent === false) {
console.log('Line: ' + lineA + ', Position: ' + characterA);
} else {
console.log(allFunctionsLIST);
}
});
在highlightEvent中创建的日志可以工作,但是因为在clickEvent中解析了某些项目/方法的位置,并且本地变量(lineA)与解析的值一起保存,所以我只能访问最后单击的项目中的
数据是我的主要问题,当右键单击某个项目并从上下文菜单中选择时,它会显示我想要的内容,但来自上次单击的项目。
右键单击项目时是否可以“左键单击”该项目,以便解析右键单击项目的数据,而不是最后一次左键单击的数据?
I'm currently working on an extension and have some trouble implementing command for right clicking elements from my TreeView (namely HomeItem elements).
I have implemented the command to simply click on an element and reveal it's location like this:
in home.ts (for treeView):
this.command = {
title: "Reveal Method",
command: "extension-home.click",
arguments: [line,character]
};
in extension.ts:
let clickEvent = vscode.commands.registerCommand('extension-home.click', (line: number, character: number) => {
lineA = line;
characterA = character;
isParent = false;
// execute vscode commandto jump to location at (line,character)
const functionPosition = new vscode.Position(line,character);
vscode.window.activeTextEditor!.selections = [new vscode.Selection(functionPosition, functionPosition)];
vscode.commands.executeCommand("workbench.action.focusActiveEditorGroup");
});
Now I got some functionality to execute a command when right clicking and choosing from the context list, with this:
let highlightEvent = vscode.commands.registerCommand('extension-home.rightClick', () => {
if (isParent === false) {
console.log('Line: ' + lineA + ', Position: ' + characterA);
} else {
console.log(allFunctionsLIST);
}
});
The logs created in highlightEvent work, but because in clickEvent the location for some item/method is parsed and the local variable (lineA) is saved with the parsed values, I can only access the data from the last clicked item
This is my main problem, when right clicking some item and selecting from the context menu, it displays what I want, but from the last clicked item.
Is is possible to 'left click' the item when it is rightclicked so the data for the right clicked item get parsed and not the last left clicked?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论