mirror of
https://github.com/alberti42/obsidian-plugins-annotations.git
synced 2026-07-22 10:10:24 +00:00
Handle nested link clicks in annotations
This commit is contained in:
parent
4845905453
commit
4a8f777602
2 changed files with 18 additions and 13 deletions
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"id": "plugins-annotations",
|
||||
"name": "Plugins Annotations",
|
||||
"version": "1.7.9",
|
||||
"version": "1.7.10",
|
||||
"minAppVersion": "1.5.0",
|
||||
"description": "Allows adding personal comments to each installed plugin.",
|
||||
"author": "Andrea Alberti",
|
||||
|
|
|
|||
|
|
@ -55,13 +55,16 @@ export class AnnotationControl {
|
|||
}
|
||||
|
||||
addEventListeners() {
|
||||
const linkInteractionHandler = (event: MouseEvent | TouchEvent) => {
|
||||
if (event.target && (event.target as HTMLElement).tagName === 'A') {
|
||||
this.clickedLink = true;
|
||||
} else {
|
||||
this.clickedLink = false;
|
||||
}
|
||||
};
|
||||
const linkInteractionHandler = (event: MouseEvent | TouchEvent) => {
|
||||
const target = event.target as HTMLElement | null;
|
||||
// Use closest('a') so clicks on nested elements (e.g., spans inside links) still register as link clicks.
|
||||
// This scenario is likely never occurring, but closest('a') keeps link detection reliable (just in case).
|
||||
if (target && target.closest('a')) {
|
||||
this.clickedLink = true;
|
||||
} else {
|
||||
this.clickedLink = false;
|
||||
}
|
||||
};
|
||||
|
||||
this.annotation_div.addEventListener('mousedown', linkInteractionHandler);
|
||||
this.annotation_div.addEventListener('touchstart', linkInteractionHandler, { passive: true });
|
||||
|
|
@ -71,11 +74,13 @@ export class AnnotationControl {
|
|||
this.annotation_div.addEventListener('click', (event:MouseEvent) => {
|
||||
if(!this.plugin.settings.editable) {
|
||||
return;
|
||||
} else {
|
||||
event.stopPropagation();
|
||||
// Explicitly focus to help mobile keyboards appear, especially on Android.
|
||||
this.annotation_div.focus();
|
||||
}
|
||||
} else {
|
||||
event.stopPropagation();
|
||||
if (!this.clickedLink) {
|
||||
// Explicitly focus to help mobile keyboards appear, especially on Android.
|
||||
this.annotation_div.focus();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
this.annotation_div.addEventListener('focus', async (event:FocusEvent) => {
|
||||
|
|
|
|||
Loading…
Reference in a new issue