From 92bc2718311933cc837eb5633608ee9e545cea3f Mon Sep 17 00:00:00 2001 From: gstjepan2 Date: Wed, 11 Jun 2025 10:55:46 +0200 Subject: [PATCH] Fixes firefox copy paste issue --- src/librustdoc/html/static/js/src-script.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/librustdoc/html/static/js/src-script.js b/src/librustdoc/html/static/js/src-script.js index b9ab6e85603bc..dfb26265080fa 100644 --- a/src/librustdoc/html/static/js/src-script.js +++ b/src/librustdoc/html/static/js/src-script.js @@ -206,6 +206,15 @@ const handleSrcHighlight = (function() { }; }()); +// Workaround for https://github.com/rust-lang/rust/issues/141464 +if (navigator.userAgent.includes("Firefox")) { + document.addEventListener("copy", e => { + const text = nonnull(window.getSelection()).toString(); + nonnull(e.clipboardData).setData("text/plain", text); + e.preventDefault(); + }); +} + window.addEventListener("hashchange", highlightSrcLines); onEachLazy(document.querySelectorAll("a[data-nosnippet]"), el => {