Visual studio code 如何在VSCode中检索活动的CustomTextEditor
我实现并注册了CustomTextEditorProvider,如 现在,我想在调用命令并且自定义编辑器处于活动状态(聚焦)时执行一个操作 问题是,如果我的编辑器处于焦点状态,api vscode.window.activeTextEditor将返回undefined。这是api的预期行为吗? 我找不到任何其他api来检索活动的非文本编辑器,有吗Visual studio code 如何在VSCode中检索活动的CustomTextEditor,visual-studio-code,Visual Studio Code,我实现并注册了CustomTextEditorProvider,如 现在,我想在调用命令并且自定义编辑器处于活动状态(聚焦)时执行一个操作 问题是,如果我的编辑器处于焦点状态,api vscode.window.activeTextEditor将返回undefined。这是api的预期行为吗? 我找不到任何其他api来检索活动的非文本编辑器,有吗 欢迎提供任何帮助Yesvscode.window。当用户关注自定义编辑器时,activeTextEditor应该是未定义的,因为自定义编辑器不是文本编
欢迎提供任何帮助Yes
vscode.window。当用户关注自定义编辑器时,activeTextEditor
应该是未定义的,因为自定义编辑器不是文本编辑器
自定义编辑器对于扩展是私有的(其他扩展应该不能与之交互),因此您需要跟踪扩展中的活动编辑器。您可以使用自定义编辑器的webview上的onDidChangeViewState
事件来执行此操作。它将在自定义编辑器聚焦和非聚焦时触发
export class MyCustomEditorProvider implements vscode.CustomTextEditorProvider{
public static register(context: vscode.ExtensionContext): vscode.Disposable {
const provider = new MyCustomEditorProvider(context);
const providerRegistration = vscode.window.registerCustomEditorProvider(MyCustomEditorProvider.viewType, provider);
return providerRegistration;
}
}