only intercept pasted links that point at an image

d372e8b · gmorell · 2026-06-23 19:59

5 files +11 -2
Message
{commit_body(@commit)}

Files changed

modified lib/waxx_web/live/board_live/show.ex
+11 −2
@@ -850,8 +850,17 @@ defmodule WaxxWeb.BoardLive.Show do
850 850 // No image bytes on the clipboard — fall back to a pasted image
851 851 // *link* (copying an image URL yields text/plain). The server
852 852 // fetches it, since the browser can't cross-origin.
853 − const text = (e.clipboardData.getData("text/plain") || "").trim();
854 − if (/^https?:\/\/\S+$/i.test(text)) {
853 + //
854 + // Never hijack a paste that's landing in a text field (note,
855 + // description, title) — those are for typing URLs and text.
856 + const t = e.target;
857 + if (t && (t.isContentEditable || t.tagName === "INPUT" ||
858 + t.tagName === "TEXTAREA" || t.tagName === "SELECT")) return;
859 +
860 + // Only intercept links that actually point at an image file, so
861 + // pasting an ordinary link elsewhere on the card is left alone.
862 + const text = ((e.clipboardData && e.clipboardData.getData("text/plain")) || "").trim();
863 + if (/^https?:\/\/\S+\.(apng|avif|bmp|gif|jpe?g|png|svg|webp)(\?\S*)?(#\S*)?$/i.test(text)) {
855 864 e.preventDefault();
856 865 this.pushEvent("set_card_background_url", { url: text });
857 866 }

Parents: ab36553