From 93c51ce6cc44a3f36a7f9d604c8700ecbba62899 Mon Sep 17 00:00:00 2001 From: piko-piko <142033278+piko-piko@users.noreply.github.com> Date: Sat, 14 Mar 2026 12:20:15 +0100 Subject: [PATCH] Middle click to open the preview card thumbnail in a new tab --- .../components/url-preview/UrlPreviewCard.tsx | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/app/components/url-preview/UrlPreviewCard.tsx b/src/app/components/url-preview/UrlPreviewCard.tsx index 129614ce..39f6fb8b 100644 --- a/src/app/components/url-preview/UrlPreviewCard.tsx +++ b/src/app/components/url-preview/UrlPreviewCard.tsx @@ -14,9 +14,17 @@ import { UrlPreview, UrlPreviewContent, UrlPreviewDescription } from './UrlPrevi import { AudioContent, ImageContent, VideoContent } from '../message'; import { Image, MediaControl, Video } from '../media'; import { ImageViewer } from '../image-viewer'; +import { downloadMedia } from '$utils/matrix'; const linkStyles = { color: color.Success.Main }; +const openMediaInNewTab = async (url: string | undefined) => { + if (!url) { console.warn("Attempted to open an empty url"); return} + const blob = await downloadMedia(url); + const blobUrl = URL.createObjectURL(blob); + window.open(blobUrl, "_blank"); +} + export const UrlPreviewCard = as<'div', { url: string; ts: number; mediaType?: string | null }>( ({ url, ts, mediaType, ...props }, ref) => { const mx = useMatrixClient(); @@ -50,6 +58,17 @@ export const UrlPreviewCard = as<'div', { url: string; ts: number; mediaType?: s 'scale', false ); + const handleAuxClick = (ev: React.MouseEvent) => { + if (!prev['og:image']) { console.warn("No image"); return; } + if (ev.button === 1) { + ev.preventDefault(); + const useAuthentication = true; + const mxcUrl = mxcUrlToHttp(mx, prev['og:image'], useAuthentication); + if (!mxcUrl) { console.error("Error converting mxc:// url."); return; }; + openMediaInNewTab(mxcUrl); + } + }; + return ( } @@ -187,7 +207,6 @@ export const UrlPreviewCard = as<'div', { url: string; ts: number; mediaType?: s ); } - return (