Skip to content

Commit

Permalink
feat: Native context-menu on ObsidianLink!
Browse files Browse the repository at this point in the history
  • Loading branch information
SkepticMystic committed Apr 5, 2024
1 parent 40ff704 commit c221120
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
10 changes: 9 additions & 1 deletion src/components/ObsidianLink.svelte
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<script lang="ts">
import { Keymap, Menu } from "obsidian";
import { log } from "src/logger";
import BreadcrumbsPlugin from "src/main";
import { active_file_store } from "src/stores/active_file";
Expand Down Expand Up @@ -35,8 +36,15 @@
hoverParent: event.currentTarget.parentElement,
});
}}
on:contextmenu={(e) => {
const menu = new Menu();

// SOURCE: https://discord.com/channels/686053708261228577/840286264964022302/1225828755252052068
plugin.app.workspace.handleLinkContextMenu(menu, display, path);

menu.showAtMouseEvent(e);
}}
on:auxclick|preventDefault={(e) => {
on:auxclick={(e) => {
log.debug("on:auxclick e.button", e.button);

if (e.button === 1) {
Expand Down
6 changes: 5 additions & 1 deletion src/interfaces/obsidian.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import "obsidian";

// TODO: https://github.com/Fevol/obsidian-typings

export type FrontmatterPropertyType =
| "text"
| "checkbox"
Expand All @@ -21,7 +23,9 @@ declare module "obsidian" {
};
}

interface Workspace {}
interface Workspace {
handleLinkContextMenu(menu: Menu, display: string, path: string): void;
}

interface Editor {}
}
Expand Down

0 comments on commit c221120

Please sign in to comment.