Replace (wiki) links with proper link widgets for better click behavior

This commit is contained in:
Zef Hemel
2022-11-28 16:56:15 +01:00
parent cab0c5aa23
commit a20aed99e2
7 changed files with 198 additions and 120 deletions
+25
View File
@@ -8,8 +8,33 @@ import {
foldedRanges,
SyntaxNodeRef,
syntaxTree,
WidgetType,
} from "../deps.ts";
export class LinkWidget extends WidgetType {
constructor(
readonly text: string,
readonly title: string,
readonly cssClass: string,
readonly callback: (e: MouseEvent) => void,
) {
super();
}
toDOM(): HTMLElement {
const anchor = document.createElement("a");
anchor.className = this.cssClass;
anchor.textContent = this.text;
anchor.addEventListener("click", (e) => {
e.preventDefault();
e.stopPropagation();
this.callback(e);
});
anchor.setAttribute("title", this.title);
anchor.href = "#";
return anchor;
}
}
/**
* Check if two ranges overlap
* Based on the visual diagram on https://stackoverflow.com/a/25369187