File tree Expand file tree Collapse file tree 1 file changed +29
-1
lines changed
src/librustdoc/html/static/js Expand file tree Collapse file tree 1 file changed +29
-1
lines changed Original file line number Diff line number Diff line change 11// Local js definitions:
22/* global addClass, getSettingValue, hasClass, updateLocalStorage */
3- /* global onEachLazy, removeClass, getVar */
3+ /* global onEachLazy, removeClass, getVar, nonnull */
44
55"use strict" ;
66
@@ -2138,3 +2138,31 @@ function preLoadCss(cssUrl) {
21382138 elem . addEventListener ( "click" , showHideCodeExampleButtons ) ;
21392139 } ) ;
21402140} ( ) ) ;
2141+
2142+ // This section is a bugfix for firefox: when copying text with `user-select: none`, it adds
2143+ // extra backline characters.
2144+ //
2145+ // Rustdoc issue: Workaround for https://github.com/rust-lang/rust/issues/141464
2146+ // Firefox issue: https://bugzilla.mozilla.org/show_bug.cgi?id=1273836
2147+ ( function ( ) {
2148+ document . body . addEventListener ( "copy" , event => {
2149+ let target = nonnull ( event . target ) ;
2150+ let isInsideCode = false ;
2151+ while ( target && target !== document . body ) {
2152+ // @ts -expect-error
2153+ if ( target . tagName === "CODE" ) {
2154+ isInsideCode = true ;
2155+ break ;
2156+ }
2157+ // @ts -expect-error
2158+ target = target . parentElement ;
2159+ }
2160+ if ( ! isInsideCode ) {
2161+ return ;
2162+ }
2163+ const selection = document . getSelection ( ) ;
2164+ // @ts -expect-error
2165+ nonnull ( event . clipboardData ) . setData ( "text/plain" , selection . toString ( ) ) ;
2166+ event . preventDefault ( ) ;
2167+ } ) ;
2168+ } ( ) ) ;
You can’t perform that action at this time.
0 commit comments