Skip to content

Commit

Permalink
fixed last of glitches (opening new tab)
Browse files Browse the repository at this point in the history
  • Loading branch information
aidan-gibson committed Mar 11, 2023
1 parent d12b747 commit c169b76
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 6 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ npm run build
- [ ] html viewer plugin
opening graph view ruins
## Known issues
* "open in new tab" (via context OR quickswitcher) when that tab is already open opens a "new tab" (out of focus but still; annoying, fix)
* graph view doesn't open in new tab
# Notes
If there is a tab open in another Obsidian window which is minimized, it will look like nothing is happening. I don't have the ability to unminimize the other window as an Obsidian plug-in (afaik).
32 changes: 29 additions & 3 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default class Opener extends Plugin {
// this.migrateSettings();
this.addSettingTab(new OpenerSettingTab(this.app, this));
this.monkeyPatchopenFile();
// this.monkeyPatchopenLinkText();
this.monkeyPatchopenLinkText();
// eslint-disable-next-line @typescript-eslint/no-explicit-any
// (this.app as any).commands.removeCommand(
// `editor:open-link-in-new-leaf`
Expand Down Expand Up @@ -56,7 +56,7 @@ export default class Opener extends Plugin {
this.uninstallMonkeyPatch = around(WorkspaceLeaf.prototype, {
openFile(oldopenFile) {
return async function (file: TFile, openState?: OpenViewState) {
console.log(openState);
// console.log(openState);
if (parentThis.settings.PDFApp && file.extension == 'pdf') {
// @ts-ignore
app.openWithDefaultApp(file.path);
Expand Down Expand Up @@ -117,7 +117,33 @@ export default class Opener extends Plugin {
});
}

// fixes editor:open-link-in-new-leaf, context menu > open in new tab, etc, command palette "open link under cursor in new tab"
// if note already exists, monkeyPatchopenFile() does its job and moves to that one. but openLinkText() with options selected for new tab (invoked via Right Click > Open in New Tab or Quick Switcher Cmd+Enter, etc) will still open a new tab.
monkeyPatchopenLinkText() {
let parentThis = this;
this.uninstallMonkeyPatch = around(Workspace.prototype, {
openLinkText(oldOpenLinkText) {
return async function (
linkText: string,
sourcePath: string,
newLeaf?: PaneType | boolean,
openViewState?: OpenViewState
) {
console.log(newLeaf);
console.log(openViewState);
if(newLeaf == 'tab'){
newLeaf = false;
}
oldOpenLinkText &&
oldOpenLinkText.apply(this, [
linkText,
sourcePath,
newLeaf,
openViewState,
]);
};
},
});
}
// monkeyPatchopenLinkText() {
// let parentThis = this;
// this.uninstallMonkeyPatch = around(Workspace.prototype, {
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "obsidian-opener",
"name": "Opener",
"version": "1.0.7",
"version": "1.0.8",
"minAppVersion": "0.15.9",
"description": "Open links in new/existing tabs by default. Open PDFs in System App by default.",
"author": "Aidan Gibson",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "obsidian-opener",
"version": "1.0.7",
"version": "1.0.8",
"description": "Open links in new/existing tabs by default. Open PDFs in System App by default.",
"main": "main.js",
"scripts": {
Expand Down

0 comments on commit c169b76

Please sign in to comment.