From 4843970e1bc3e58019c270945b71c42180d6178c Mon Sep 17 00:00:00 2001 From: Lim Chee Aun Date: Sat, 9 Mar 2024 17:01:50 +0800 Subject: [PATCH] Custom context menu if link has hash --- src/components/status.jsx | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/components/status.jsx b/src/components/status.jsx index 03bd897..2b56ff2 100644 --- a/src/components/status.jsx +++ b/src/components/status.jsx @@ -1100,7 +1100,12 @@ function Status({ const { clientX, clientY } = e.touches?.[0] || e; // link detection copied from onContextMenu because here it works const link = e.target.closest('a'); - if (link && statusRef.current.contains(link)) return; + if ( + link && + statusRef.current.contains(link) && + !link.getAttribute('href').startsWith('#') + ) + return; e.preventDefault(); setContextMenuProps({ anchorPoint: { @@ -1346,7 +1351,12 @@ function Status({ if (e.metaKey) return; // console.log('context menu', e); const link = e.target.closest('a'); - if (link && statusRef.current.contains(link)) return; + if ( + link && + statusRef.current.contains(link) && + !link.getAttribute('href').startsWith('#') + ) + return; // If there's selected text, don't show custom context menu const selection = window.getSelection?.();