From f5b0049bf027b15ca2484bba33c332e3d5e5595f Mon Sep 17 00:00:00 2001 From: Moritz Jung Date: Tue, 5 Nov 2024 21:22:36 +0100 Subject: [PATCH] implement #436 --- exampleVault/Buttons/Button Example.md | 4 ++-- packages/core/src/config/ButtonConfigValidators.ts | 4 ++-- .../src/fields/button/actions/OpenButtonActionConfig.ts | 7 ++++--- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/exampleVault/Buttons/Button Example.md b/exampleVault/Buttons/Button Example.md index df402a44..1bd34284 100644 --- a/exampleVault/Buttons/Button Example.md +++ b/exampleVault/Buttons/Button Example.md @@ -18,11 +18,11 @@ With a custom class and a CSS snippet we can change the button to be green. ```meta-bind-button style: primary -label: Open Meta Bind FAQ +label: Open Meta Bind Playground class: green-button action: type: command - command: obsidian-meta-bind-plugin:open-faq + command: obsidian-meta-bind-plugin:open-playground ``` And custom JS buttons as well diff --git a/packages/core/src/config/ButtonConfigValidators.ts b/packages/core/src/config/ButtonConfigValidators.ts index 211c8b6d..e404b750 100644 --- a/packages/core/src/config/ButtonConfigValidators.ts +++ b/packages/core/src/config/ButtonConfigValidators.ts @@ -165,7 +165,7 @@ export const V_InsertIntoNoteButtonAction = schemaForType()( +export const V_InlineJSButtonAction = schemaForType()( z.object({ type: z.literal(ButtonActionType.INLINE_JS), code: stringValidator('inlineJS', 'code', 'code string to run'), @@ -186,7 +186,7 @@ export const V_ButtonAction = schemaForType()( V_ReplaceSelfButtonAction, V_RegexpReplaceInNoteButtonAction, V_InsertIntoNoteButtonAction, - V_InlineJsButtonAction, + V_InlineJSButtonAction, ]), ); diff --git a/packages/core/src/fields/button/actions/OpenButtonActionConfig.ts b/packages/core/src/fields/button/actions/OpenButtonActionConfig.ts index 98c4ed0d..d2f7ab83 100644 --- a/packages/core/src/fields/button/actions/OpenButtonActionConfig.ts +++ b/packages/core/src/fields/button/actions/OpenButtonActionConfig.ts @@ -4,7 +4,7 @@ import type { ButtonContext, OpenButtonAction, } from 'packages/core/src/config/ButtonConfig'; -import { ButtonActionType } from 'packages/core/src/config/ButtonConfig'; +import { ButtonActionType, ButtonClickType } from 'packages/core/src/config/ButtonConfig'; import { AbstractButtonActionConfig } from 'packages/core/src/fields/button/AbstractButtonActionConfig'; import type { IPlugin } from 'packages/core/src/IPlugin'; import { MDLinkParser } from 'packages/core/src/parsers/MarkdownLinkParser'; @@ -19,9 +19,10 @@ export class OpenButtonActionConfig extends AbstractButtonActionConfig { - MDLinkParser.parseLinkOrUrl(action.link).open(this.plugin, filePath, action.newTab ?? false); + const newTab = click.type === ButtonClickType.MIDDLE || click.ctrlKey || (action.newTab ?? false); + MDLinkParser.parseLinkOrUrl(action.link).open(this.plugin, filePath, newTab); } create(): Required {