从vscode自定义文本编辑器扩展程序中重新打开默认编辑器中的文件
我正在创建VSCODE CustomTextEditor扩展程序。 扩展名在YAML文件上激活,但设计仅支持其中的一小部分。 不是可以通过文件名/扩展名或文件的第一行可靠地检测支持的文件。
我希望扩展名在VSCODE的标准文本编辑器中重新打开未支撑的文件,以使用户体验不会降低。
我尝试使用“ workbench.action.reopenwitheditor”命令,它仅显示用户必须注意的编辑器选择菜单,然后单击。
我尝试使用“ vscode.openwith”命令在默认文本编辑器中打开文件。该文件打开,但不能替换原始的自定义编辑器选项卡,该选项卡保持空白。
如何在默认文本编辑器中编程重新打开当前文件?
re rep open
current
public async resolveCustomTextEditor(
document: vscode.TextDocument,
webviewPanel: vscode.WebviewPanel,
_token: vscode.CancellationToken
): Promise<void> {
const documentText = document.getText();
if (!documentText.match(/implementation:\s*graph:/))) {
vscode.commands.executeCommand(
"vscode.openWith",
document.uri,
"default",
webviewPanel.viewColumn
);
// Not loading HTML into the webview
return;
}
...
}
I'm creating a VSCode CustomTextEditor extension.
The extension activates on YAML files, but by design only supports a small subset of them. It's not possible to reliably detect supported files by file name/extension or the first line of the file.
I want the extension to reopen the unsupported files in VSCode's standard text editor so that the user experience is not degraded.
I've tried to use the "workbench.action.reopenWithEditor" command, it just shows the editor selection menu that the user must notice and click.
I've tried to use the "vscode.openWith" command to open the file in the default text editor. The file opens, but it does not replace the original custom editor tab which remains blank.
How can I programmatically reopen the current file in the default text editor?
reopen
current
public async resolveCustomTextEditor(
document: vscode.TextDocument,
webviewPanel: vscode.WebviewPanel,
_token: vscode.CancellationToken
): Promise<void> {
const documentText = document.getText();
if (!documentText.match(/implementation:\s*graph:/))) {
vscode.commands.executeCommand(
"vscode.openWith",
document.uri,
"default",
webviewPanel.viewColumn
);
// Not loading HTML into the webview
return;
}
...
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用以下命令在打开默认一个之前关闭活动的WebView编辑器:
You can use the following command to close the active webview editor before opening the default one: