Skip to content

Commit

Permalink
feat: add newpane parameter
Browse files Browse the repository at this point in the history
close #50
  • Loading branch information
Vinzent03 committed Mar 24, 2022
1 parent f75713d commit cf2dd3c
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 15 deletions.
2 changes: 1 addition & 1 deletion docs/docs/actions/navigation.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@ obsidian://advanced-uri?vault=<your-vault>&filepath=my-file&block=12345
:::

:::tip
You can specify a custom [view mode](../concepts/view_mode.md)
You can specify a custom [view mode](../concepts/navigation_parameters.md)
:::
22 changes: 22 additions & 0 deletions docs/docs/concepts/navigation_parameters.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
sidebar_position: 4
---

# Navigation Parameters

## View mode

Every action opening or focusing a pane supports the parameter `viewmode`. Accepted values:
- `source`: Sets the editor to reading:source mode
- `live`: Sets the editor to reading:live mode
- `preview`: Sets the editor to preview mode

## New pane

Every action opening a pane supports the parameter `newpane`. Accepted values:
- `true` opens file in a new pane if not already opened
- `false` opens file in current pane if not already opened

If the file is already opened in another pane, it gets focused.

You can set a default value in the plugin's settings. The value from the setting gets overwritten by specifying it in the URI.
10 changes: 0 additions & 10 deletions docs/docs/concepts/view_mode.md

This file was deleted.

12 changes: 8 additions & 4 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -407,8 +407,10 @@ export default class AdvancedURI extends Plugin {
await leaf.setViewState(viewState);
}
}

const openInNewPane = parameters.newpane !== undefined ? parameters.newpane == "true" : this.settings.openFileWithoutWriteInNewPane;
if (parameters.heading != undefined) {
await this.app.workspace.openLinkText(parameters.filepath + "#" + parameters.heading, "", this.settings.openFileWithoutWriteInNewPane, this.getViewStateFromMode(parameters));
await this.app.workspace.openLinkText(parameters.filepath + "#" + parameters.heading, "", openInNewPane, this.getViewStateFromMode(parameters));
const view = this.app.workspace.getActiveViewOfType(MarkdownView);
if (!view) return;
const cache = this.app.metadataCache.getFileCache(view.file);
Expand All @@ -417,7 +419,7 @@ export default class AdvancedURI extends Plugin {
view.editor.setCursor({ line: heading.position.start.line + 1, ch: 0 });
}
else if (parameters.block != undefined) {
await this.app.workspace.openLinkText(parameters.filepath + "#^" + parameters.block, "", this.settings.openFileWithoutWriteInNewPane, this.getViewStateFromMode(parameters));
await this.app.workspace.openLinkText(parameters.filepath + "#^" + parameters.block, "", openInNewPane, this.getViewStateFromMode(parameters));
const view = this.app.workspace.getActiveViewOfType(MarkdownView);
if (!view) return;
const cache = this.app.metadataCache.getFileCache(view.file);
Expand All @@ -427,7 +429,7 @@ export default class AdvancedURI extends Plugin {
}
else {
if (!fileIsAlreadyOpened)
await this.app.workspace.openLinkText(parameters.filepath, "", this.settings.openFileWithoutWriteInNewPane, this.getViewStateFromMode(parameters));
await this.app.workspace.openLinkText(parameters.filepath, "", openInNewPane, this.getViewStateFromMode(parameters));
if (parameters.line != undefined) {
this.setCursorInLine(parameters.line);
}
Expand Down Expand Up @@ -536,8 +538,10 @@ export default class AdvancedURI extends Plugin {
this.app.workspace.setActiveLeaf(leaf, true, true);
}
});
console.log(parameters);

if (!fileIsAlreadyOpened)
await this.app.workspace.openLinkText(outputFileName, "", this.settings.openFileOnWriteInNewPane, this.getViewStateFromMode(parameters));
await this.app.workspace.openLinkText(outputFileName, "", parameters.newpane !== undefined ? parameters.newpane == "true" : this.settings.openFileOnWriteInNewPane, this.getViewStateFromMode(parameters));
if (parameters.line != undefined) {
this.setCursorInLine(parameters.line);
}
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ export interface Parameters {
saveworkspace?: "true";
updateplugins?: "true";
line?: number;
newpane?: "true" | "false";
}

export interface HookParameters {
Expand Down

0 comments on commit cf2dd3c

Please sign in to comment.