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) {
2248
2248
if ( ! isInsideCode ) {
2249
2249
return ;
2250
2250
}
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 ) ;
2254
2262
event . preventDefault ( ) ;
2255
2263
} ) ;
2256
2264
} ( ) ) ;
You can’t perform that action at this time.
0 commit comments