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 @@ -206,6 +206,31 @@ const handleSrcHighlight = (function() {
206206 } ;
207207} ( ) ) ;
208208
209+ // This section is a bugfix for firefox: when copying text with `user-select: none`, it adds
210+ // extra backline characters.
211+ //
212+ // Rustdoc issue: Workaround for https://github.com/rust-lang/rust/issues/141464
213+ // Firefox issue: https://bugzilla.mozilla.org/show_bug.cgi?id=1273836
214+ ( function ( ) {
215+ document . body . addEventListener ( "copy" , event => {
216+ let target = event . target ;
217+ let isInsideCode = false ;
218+ while ( target !== document . body ) {
219+ if ( target . tagName === "CODE" ) {
220+ isInsideCode = true ;
221+ break ;
222+ }
223+ target = target . parentElement ;
224+ }
225+ if ( ! isInsideCode ) {
226+ return ;
227+ }
228+ const selection = document . getSelection ( ) ;
229+ nonnull ( event . clipboardData ) . setData ( "text/plain" , selection . toString ( ) ) ;
230+ event . preventDefault ( ) ;
231+ } ) ;
232+ } ( ) ) ;
233+
209234window . addEventListener ( "hashchange" , highlightSrcLines ) ;
210235
211236onEachLazy ( document . querySelectorAll ( "a[data-nosnippet]" ) , el => {
You can’t perform that action at this time.
0 commit comments