diff --git a/CHANGELOG.md b/CHANGELOG.md index 9c80c7ab..2e57b8d5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ - [#937](https://github.com/estruyf/vscode-front-matter/issues/937): Dashboard "Structure" view for documentation sites *WIP* - [#965](https://github.com/estruyf/vscode-front-matter/issues/965): Added SEO support for the keyword in the first paragraph - [#973](https://github.com/estruyf/vscode-front-matter/issues/973): Support for number fields in the snippets +- [#1005](https://github.com/estruyf/vscode-front-matter/issues/1005): Support the integrated VSCode browser for the preview command ### 🐞 Fixes diff --git a/src/commands/Preview.ts b/src/commands/Preview.ts index d537b37c..5ddbc5b1 100644 --- a/src/commands/Preview.ts +++ b/src/commands/Preview.ts @@ -54,6 +54,7 @@ export class Preview { return; } + const integratedBrowserCommand = await this.getIntegratedBrowserCommand(); const browserLiteCommand = await this.getBrowserLiteCommand(); const editor = window.activeTextEditor; @@ -69,6 +70,12 @@ export class Preview { const slug = await this.getContentSlug(article, editor?.document.uri.fsPath); const localhostUrl = await this.getLocalServerUrl(); + if (integratedBrowserCommand) { + const pageUrl = joinUrl(localhostUrl.toString(), slug || ''); + commands.executeCommand(integratedBrowserCommand, pageUrl); + return; + } + if (browserLiteCommand) { const pageUrl = joinUrl(localhostUrl.toString(), slug || ''); commands.executeCommand(browserLiteCommand, pageUrl); @@ -368,6 +375,17 @@ export class Preview { return undefined; } + /** + * Check if Browser Lite is installed + */ + private static async getIntegratedBrowserCommand() { + const allCommands = await commands.getCommands(true); + if (allCommands.includes(`workbench.action.browser.open`)) { + return `workbench.action.browser.open`; + } + return undefined; + } + /** * Retrieve the localhost url * @returns diff --git a/src/extension.ts b/src/extension.ts index 6ddf29ae..643615e6 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -194,7 +194,7 @@ export async function activate(context: vscode.ExtensionContext) { subscriptions.push( vscode.commands.registerCommand(COMMAND_NAME.docs, () => { vscode.commands.executeCommand( - `simpleBrowser.show`, + `workbench.action.browser.open`, `https://${extension.isBetaVersion() ? `beta.` : ``}frontmatter.codes/docs` ); })