Tra*_*mot 5 visual-studio-code vscode-extensions vscode-tasks
我正在开发一个 Visual Studio Code 扩展,用于打开 webview 自定义编辑器。
其中一部分是一条命令,提示用户输入文件名、创建文件,然后打开它。
它看起来像这样:
window
.showInputBox({
prompt: "Enter name for file",
})
.then((title) => {
if (!title) {
return;
}
const fileContent = generateDefaultFileContent();
const filePath = path.join(folder.uri.path, `${title}.custom_file_format`);
workspace.fs
.writeFile(
folder.uri.with({
path: filePath,
}),
Buffer.from(fileContent, "utf8")
)
.then(() => {
workspace.openTextDocument(filePath).then((doc) =>
window.showTextDocument(doc, {
viewColumn: ViewColumn.Active,
})
);
});
});
Run Code Online (Sandbox Code Playgroud)
文件已正确创建,但是调用会window.showTextDocument
在文本编辑器中打开编辑器,而不是我注册的自定义编辑器(在上面的示例中,自定义编辑器将打开.custom_file_format
文件)。如果您在文件资源管理器中单击新创建的文件,它将在自定义编辑器中打开。
有没有办法让它在自定义编辑器中打开新文件?
事实证明这可以通过...来完成
commands.executeCommand(
"vscode.openWith",
folder.uri.with({
path: filePath,
}),
MyCustomEditor.viewType
);
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1392 次 |
最近记录: |