From a308e6ecb85ab2fc1d2fc17f3c9b638e9d3720e3 Mon Sep 17 00:00:00 2001 From: brecert Date: Tue, 7 Sep 2021 09:09:12 -0400 Subject: [PATCH] Add `shift+click` to mention mentions --- src/components/markdown/Renderer.tsx | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/components/markdown/Renderer.tsx b/src/components/markdown/Renderer.tsx index d484cc2d..01a850e2 100644 --- a/src/components/markdown/Renderer.tsx +++ b/src/components/markdown/Renderer.tsx @@ -44,7 +44,7 @@ if (typeof window !== "undefined") { if (code) { navigator.clipboard.writeText(code.textContent?.trim() ?? ""); } - } catch (e) {} + } catch (e) { } }; } @@ -140,7 +140,18 @@ export default function Renderer({ content, disallowBigEmoji }: MarkdownProps) { (ev: MouseEvent) => { if (ev.currentTarget) { const element = ev.currentTarget as HTMLAnchorElement; - if (openLink(element.href)) ev.preventDefault(); + if (element.dataset.type === 'mention' && ev.shiftKey) { + internalEmit( + "MessageBox", + "append", + `<@${element.dataset.mentionId}>`, + "mention", + ); + + ev.preventDefault() + } else if (openLink(element.href)) { + ev.preventDefault(); + } } }, [openLink], @@ -162,6 +173,7 @@ export default function Renderer({ content, disallowBigEmoji }: MarkdownProps) { element.removeEventListener("click", handleLink); element.addEventListener("click", handleLink); element.removeAttribute("data-type"); + element.removeAttribute("data-mention-id"); element.removeAttribute("target"); const link = determineLink(element.href); @@ -171,6 +183,10 @@ export default function Renderer({ content, disallowBigEmoji }: MarkdownProps) { "data-type", "mention", ); + element.setAttribute( + "data-mention-id", + link.id + ) break; } case "external": {