Skip to content

Commit

Permalink
[FIX] Adds Workspace overload for search results menu (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
czottmann committed May 2, 2023
1 parent 5005a81 commit 0d0c6ac
Showing 1 changed file with 25 additions and 18 deletions.
43 changes: 25 additions & 18 deletions main.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import { Notice, Plugin, setIcon } from "obsidian";
import { Menu, Notice, Plugin } from "obsidian";
import { SearchLeafView } from "./types";

export default class CopySearchUrl extends Plugin {
button: HTMLDivElement;
declare module "obsidian" {
interface Workspace {
on(name: "search:results-menu", callback: (menu: Menu) => any): EventRef;
}
}

export default class CopySearchUrl extends Plugin {
async onload() {
this.app.workspace.onLayoutReady(() => {
if (this.isSearchDisabled()) {
Expand All @@ -14,21 +18,24 @@ export default class CopySearchUrl extends Plugin {
}

this.registerEvent(
this.app.workspace.on("search:results-menu", (menu, file) => {
menu.addItem((item) => {
item
.setTitle("Copy Obsidian search URL")
.setIcon("link")
.onClick(async () => {
if (this.getSearchQuery() === "") {
return;
}

await navigator.clipboard.writeText(this.getObsidianUrl());
new Notice("Obsidian search URL copied!");
});
});
}),
this.app.workspace.on(
"search:results-menu",
(menu: Menu) => {
menu.addItem((item) => {
item
.setTitle("Copy Obsidian search URL")
.setIcon("link")
.onClick(async () => {
if (this.getSearchQuery() === "") {
return;
}

await navigator.clipboard.writeText(this.getObsidianUrl());
new Notice("Obsidian search URL copied!");
});
});
},
),
);
});
}
Expand Down

0 comments on commit 0d0c6ac

Please sign in to comment.