Skip to content

Commit eb21509

Browse files
committed
fix #178
1 parent 367bb65 commit eb21509

File tree

8 files changed

+20
-7
lines changed

8 files changed

+20
-7
lines changed

exampleVault/Button Example.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,17 @@ action:
3636
link: "[[View Fields/Other Note|Other Note]]"
3737
```
3838

39+
```meta-bind-button
40+
style: primary
41+
id: open-tab-button
42+
hidden: true
43+
label: Open File new Tab
44+
action:
45+
type: open
46+
newTab: true
47+
link: "[[View Fields/Other Note|Other Note]]"
48+
```
49+
3950
```meta-bind-button
4051
style: default
4152
id: docs-button
@@ -46,7 +57,7 @@ action:
4657
link: https://www.moritzjung.dev/obsidian-meta-bind-plugin-docs/
4758
```
4859

49-
text `BUTTON[docs-button, open-button]` text
60+
text `BUTTON[docs-button, open-button, open-tab-button]` text
5061

5162
```meta-bind-button
5263
label: Switch to Light Mode

src/api/internalApi/IInternalAPI.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export interface IInternalAPI {
3030

3131
jsEngineRunCode(code: string, callingFilePath: string, container?: HTMLElement): Promise<() => void>;
3232

33-
openFile(filePath: string, callingFilePath: string): void;
33+
openFile(filePath: string, callingFilePath: string, newTab: boolean): void;
3434

3535
getFilePathByName(name: string): string | undefined;
3636

src/api/internalApi/ObsidianAPIAdapter.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,8 @@ export class ObsidianAPIAdapter implements IInternalAPI {
107107
return () => component.unload();
108108
}
109109

110-
public openFile(filePath: string, callingFilePath: string): void {
111-
void this.app.workspace.openLinkText(filePath, callingFilePath, true);
110+
public openFile(filePath: string, callingFilePath: string, newTab: boolean): void {
111+
void this.app.workspace.openLinkText(filePath, callingFilePath, newTab);
112112
}
113113

114114
public getFilePathByName(name: string): string | undefined {

src/api/internalApi/PublishAPIAdapter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export class PublishAPIAdapter implements IInternalAPI {
4747
return Promise.reject(new Error('not implemented'));
4848
}
4949

50-
public openFile(_filePath: string, _callingFilePath: string): void {
50+
public openFile(_filePath: string, _callingFilePath: string, _newTab: boolean): void {
5151
throw new Error('not implemented');
5252
}
5353

src/config/ButtonConfig.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export interface JSButtonAction {
2828
export interface OpenButtonAction {
2929
type: ButtonActionType.OPEN;
3030
link: string;
31+
newTab?: boolean;
3132
}
3233

3334
export interface InputButtonAction {

src/config/ButtonConfigValidators.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export const V_OpenButtonAction = schemaForType<OpenButtonAction>()(
3232
z.object({
3333
type: z.literal(ButtonActionType.OPEN),
3434
link: z.string(),
35+
newTab: z.boolean().optional(),
3536
}),
3637
);
3738

src/fields/button/ButtonActionRunner.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ export class ButtonActionRunner {
111111
async runOpenAction(action: OpenButtonAction, filePath: string): Promise<void> {
112112
const link = MDLinkParser.parseLinkOrUrl(action.link);
113113
if (link.internal) {
114-
this.plugin.internal.openFile(link.target, filePath);
114+
this.plugin.internal.openFile(link.target, filePath, action.newTab ?? false);
115115
} else {
116116
openURL(link.target);
117117
}

tests/__mocks__/TestAPIAdapter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export class TestAPIAdapter implements IInternalAPI {
4646
return Promise.reject(new Error('not implemented'));
4747
}
4848

49-
public openFile(_filePath: string, _callingFilePath: string): void {
49+
public openFile(_filePath: string, _callingFilePath: string, _newTab: boolean): void {
5050
throw new Error('not implemented');
5151
}
5252

0 commit comments

Comments
 (0)