diff --git a/external/lang b/external/lang index 4cfba33b..42a88568 160000 --- a/external/lang +++ b/external/lang @@ -1 +1 @@ -Subproject commit 4cfba33bf590ccaec2ad957c43bec14b14ed2f8b +Subproject commit 42a8856899a6698fff3d3d6b332e343d6384e081 diff --git a/src/components/common/messaging/embed/Embed.tsx b/src/components/common/messaging/embed/Embed.tsx index ce63c1aa..d54135d4 100644 --- a/src/components/common/messaging/embed/Embed.tsx +++ b/src/components/common/messaging/embed/Embed.tsx @@ -142,7 +142,11 @@ export default function Embed({ embed }: Props) { (ev.button === 0 || ev.button === 1) && - modalController.openLink(embed.url!) + modalController.openLink( + embed.url!, + undefined, + true, + ) } className={styles.title}> {embed.title} @@ -194,7 +198,8 @@ export default function Embed({ embed }: Props) { modalController.push({ type: "image_viewer", embed }) } onMouseDown={(ev) => - ev.button === 1 && modalController.openLink(embed.url) + ev.button === 1 && + modalController.openLink(embed.url, undefined, true) } /> ); diff --git a/src/components/markdown/plugins/anchors.tsx b/src/components/markdown/plugins/anchors.tsx index 8d616247..37b8bb15 100644 --- a/src/components/markdown/plugins/anchors.tsx +++ b/src/components/markdown/plugins/anchors.tsx @@ -27,7 +27,11 @@ export function RenderAnchor({ target="_blank" rel="noreferrer" onClick={(ev) => - modalController.openLink(href) && ev.preventDefault() + modalController.openLink( + href, + undefined, + ev.currentTarget.innerText !== href, + ) && ev.preventDefault() } /> ); diff --git a/src/controllers/modals/ModalController.tsx b/src/controllers/modals/ModalController.tsx index e7dc2ad4..62ed8073 100644 --- a/src/controllers/modals/ModalController.tsx +++ b/src/controllers/modals/ModalController.tsx @@ -208,12 +208,25 @@ class ModalControllerExtended extends ModalController { * Safely open external or internal link * @param href Raw URL * @param trusted Whether we trust this link + * @param mismatch Whether to always open link warning * @returns Whether to cancel default event */ - openLink(href?: string, trusted?: boolean) { + openLink(href?: string, trusted?: boolean, mismatch?: boolean) { const link = determineLink(href); const settings = getApplicationState().settings; + if (mismatch) { + if (href) { + modalController.push({ + type: "link_warning", + link: href, + callback: () => this.openLink(href, true) as true, + }); + } + + return true; + } + switch (link.type) { case "navigate": { history.push(link.path);