File tree Expand file tree Collapse file tree 1 file changed +11
-3
lines changed
src/librustdoc/html/static/js Expand file tree Collapse file tree 1 file changed +11
-3
lines changed Original file line number Diff line number Diff line change @@ -2248,9 +2248,17 @@ function preLoadCss(cssUrl) {
22482248 if ( ! isInsideCode ) {
22492249 return ;
22502250 }
2251- const selection = document . getSelection ( ) ;
2252- // @ts -expect-error
2253- nonnull ( event . clipboardData ) . setData ( "text/plain" , selection . toString ( ) ) ;
2251+ // On Chrome, the line numbers are copied when copying from a code block.
2252+ // Remove them from the selection.
2253+ //
2254+ // Issue: https://github.com/rust-lang/rust/issues/146816
2255+ const selection = nonnull ( document . getSelection ( ) ) ;
2256+ const text = Array . from ( { length : selection . rangeCount } , ( _ , i ) => {
2257+ const fragment = selection . getRangeAt ( i ) . cloneContents ( ) ;
2258+ fragment . querySelectorAll ( "[data-nosnippet]" ) . forEach ( el => el . remove ( ) ) ;
2259+ return fragment . textContent ;
2260+ } ) . join ( "" ) ;
2261+ nonnull ( event . clipboardData ) . setData ( "text/plain" , text ) ;
22542262 event . preventDefault ( ) ;
22552263 } ) ;
22562264} ( ) ) ;
You can’t perform that action at this time.
0 commit comments