From 3842777f71e351a9a93dfc0e16d351674a740322 Mon Sep 17 00:00:00 2001 From: Elio Struyf Date: Tue, 19 Mar 2024 12:24:08 +0100 Subject: [PATCH] #778 - Open file or webpage --- CHANGELOG.md | 1 + src/helpers/CustomScript.ts | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 91324662..f84ef0ee 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ - [#773](https://github.com/estruyf/vscode-front-matter/issues/773): Added the ability to rename content files - [#777](https://github.com/estruyf/vscode-front-matter/issues/777): Show an error in the metadata panel if something went wrong while parsing the front matter +- [#778](https://github.com/estruyf/vscode-front-matter/issues/778): Added the ability to open a file or webpage when custom scripts is completed ### ⚡️ Optimizations diff --git a/src/helpers/CustomScript.ts b/src/helpers/CustomScript.ts index bc9ba5cb..edf63f65 100644 --- a/src/helpers/CustomScript.ts +++ b/src/helpers/CustomScript.ts @@ -1,7 +1,7 @@ import { Settings } from './SettingsHelper'; import { CommandType, EnvironmentType } from './../models/PanelSettings'; import { CustomScript as ICustomScript, ScriptType } from '../models/PanelSettings'; -import { window, env as vscodeEnv, ProgressLocation } from 'vscode'; +import { window, env as vscodeEnv, ProgressLocation, Uri, commands } from 'vscode'; import { ArticleHelper, Logger, Telemetry } from '.'; import { Folders, WORKSPACE_PLACEHOLDER } from '../commands/Folders'; import { exec, execSync } from 'child_process'; @@ -301,6 +301,11 @@ export class CustomScript { l10n.t(LocalizationKey.helpersCustomScriptShowOutputFrontMatterSuccess, script.title) ); } + } else if (data.fmAction) { + if (data.fmAction === 'open' && data.fmPath) { + const uri = data.fmPath.startsWith(`http`) ? data.fmPath : Uri.file(data.fmPath); + commands.executeCommand('vscode.open', uri); + } } else { Logger.error(`No frontmatter found.`); throw new Error(`No frontmatter found.`);