簡體   English   中英

如何使用 VSCode api 打開自定義編輯器

[英]How to open Custom Editor with VSCode api

我有一個為特定文件類型注冊 CustomEditorProvider 的擴展,我需要創建一個命令,用我的編輯器打開給定的文件。

如果我從工作區資源管理器中單擊該文件,我的編輯器將正確打開,但如果我使用 showTextDocument api,則內置文本編輯器將打開。

private openModule(file:vscode.Uri) {
    vscode.workspace.openTextDocument(file).then((doc: vscode.TextDocument) => {
          vscode.window.showTextDocument(doc);
    });
  }

在 UI 中打開的編輯器上,我可以“使用...重新打開編輯器”,提示我選擇編輯器。 如果選擇我的自定義編輯器,它將使用正確的編輯器重新打開。

編輯器提供者選擇

如何強制 TextEditor 使用自定義而不是內置?

任何幫助表示贊賞

我遇到了同樣的問題,並在這里找到了我的答案:

https://github.com/microsoft/vscode/issues/98473#issuecomment-634306217

commands.executeCommand("vscode.openWith", uri, MyCustomEditor.viewType);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM