Skip to content

Commit e6dbacb

Browse files
committed
fix issues in release pull request obsidianmd/obsidian-releases#359
1 parent 968c66d commit e6dbacb

File tree

3 files changed

+17
-18
lines changed

3 files changed

+17
-18
lines changed

main.ts

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,12 @@ import {
33
} from "obsidian";
44

55
interface Listener {
6-
(this: HTMLElement, ev: Event, delegateTarget: HTMLElement): any;
7-
}
8-
interface HTMLElement {
9-
on(this: HTMLElement, type: string, selector: string, listener: Listener, options?: { capture?: boolean; }): void;
10-
off(this: HTMLElement, type: string, selector: string, listener: Listener, options?: { capture?: boolean; }): void;
6+
(this: Document, ev: Event): any;
117
}
128

139
function onElement(
14-
el: HTMLElement,
15-
event: string,
10+
el: Document,
11+
event: keyof HTMLElementEventMap,
1612
selector: string,
1713
listener: Listener,
1814
options?: { capture?: boolean; }
@@ -26,10 +22,9 @@ export default class CopyUrlInPreview extends Plugin {
2622
this.register(
2723
onElement(
2824
document,
29-
"contextmenu",
30-
".external-link",
31-
this.onClick.bind(this),
32-
{ capture: true }
25+
"contextmenu" as keyof HTMLElementEventMap,
26+
"a.external-link",
27+
this.onClick.bind(this)
3328
)
3429
);
3530
}
@@ -38,29 +33,33 @@ export default class CopyUrlInPreview extends Plugin {
3833
// Positions are not accurate from PointerEvent.
3934
// There's also TouchEvent
4035
// The event has target, path, toEvent (null on Android) for finding the link
41-
onClick(event: (MouseEvent) & { target: { href: string }, contextMenu: Menu }) {
36+
onClick(event: MouseEvent) {
37+
if (!(event.target instanceof HTMLAnchorElement)) {
38+
return;
39+
}
40+
let link = event.target.href;
41+
4242
const menu = new Menu(this.app);
4343
menu.addItem((item: MenuItem) =>
4444
item.setIcon("link")
4545
.setTitle("Copy url")
4646
.onClick(() => {
47-
navigator.clipboard.writeText(event.target.href);
47+
navigator.clipboard.writeText(link);
4848
new Notice("Url copied to your clipboard");
4949
})
5050
);
5151
menu.register(
5252
onElement(
5353
document,
54-
"keydown",
54+
"keydown" as keyof HTMLElementEventMap,
5555
"*",
5656
(e: KeyboardEvent) => {
5757
if (e.key === "Escape") {
5858
e.preventDefault();
5959
e.stopPropagation();
6060
menu.hide();
6161
}
62-
},
63-
{ capture: true }
62+
}
6463
)
6564
);
6665
menu.showAtPosition({ x: event.pageX, y: event.pageY });

manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"id": "copy-url-in-preview",
33
"name": "Copy URL in preview",
4-
"version": "1.0.0",
4+
"version": "1.0.1",
55
"minAppVersion": "0.11.13",
66
"description": "Copy URL context menu in preview mode",
77
"author": "NomarCub",

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "copy-url-in-preview",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"description": "Copy URL context menu in preview mode for Obsidian (https://obsidian.md)",
55
"main": "main.js",
66
"scripts": {

0 commit comments

Comments
 (0)