File tree Expand file tree Collapse file tree 1 file changed +25
-0
lines changed
src/librustdoc/html/static/js Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -2138,3 +2138,28 @@ function preLoadCss(cssUrl) {
2138
2138
elem . addEventListener ( "click" , showHideCodeExampleButtons ) ;
2139
2139
} ) ;
2140
2140
} ( ) ) ;
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 = event . target ;
2150
+ let isInsideCode = false ;
2151
+ while ( target !== document . body ) {
2152
+ if ( target . tagName === "CODE" ) {
2153
+ isInsideCode = true ;
2154
+ break ;
2155
+ }
2156
+ target = target . parentElement ;
2157
+ }
2158
+ if ( ! isInsideCode ) {
2159
+ return ;
2160
+ }
2161
+ const selection = document . getSelection ( ) ;
2162
+ nonnull ( event . clipboardData ) . setData ( "text/plain" , selection . toString ( ) ) ;
2163
+ event . preventDefault ( ) ;
2164
+ } ) ;
2165
+ } ( ) ) ;
You can’t perform that action at this time.
0 commit comments