File tree Expand file tree Collapse file tree 4 files changed +22
-6
lines changed Expand file tree Collapse file tree 4 files changed +22
-6
lines changed Original file line number Diff line number Diff line change @@ -317,7 +317,8 @@ export const quartoDefaults = (format: Format) => {
317317 "code-copy-selector" ,
318318 format . metadata [ kCodeCopy ] === undefined ||
319319 format . metadata [ kCodeCopy ] === "hover"
320- ? '"pre.sourceCode:hover > "'
320+ // ? '"div.sourceCode:hover > "'
321+ ? '"div.code-copy-outer-scaffold:hover > "'
321322 : '""' ,
322323 ) ,
323324 ) ,
Original file line number Diff line number Diff line change @@ -750,12 +750,25 @@ function htmlFormatPostprocessor(
750750
751751 // insert code copy button (with specfic attribute when inside a modal)
752752 if ( codeCopy ) {
753- code . classList . add ( "code-with-copy" ) ;
753+ // the interaction of code copy button fixed position
754+ // and scrolling overflow behavior requires a scaffold div to be inserted
755+ // as a parent of the code block and the copy button both
756+ // (see #13009, #5538, and #12787)
757+ const outerScaffold = doc . createElement ( "div" ) ;
758+ outerScaffold . classList . add ( "code-copy-outer-scaffold" ) ;
759+
754760 const copyButton = createCodeCopyButton ( doc , format ) ;
755761 if ( EmbedSourceModal && EmbedSourceModal . contains ( code ) ) {
756762 copyButton . setAttribute ( "data-in-quarto-modal" , "" ) ;
757763 }
758- code . appendChild ( copyButton ) ;
764+ code . classList . add ( "code-with-copy" ) ;
765+
766+ const sourceCodeDiv = code . parentElement ! ;
767+ const sourceCodeDivParent = code . parentElement ?. parentElement ;
768+ sourceCodeDivParent ! . replaceChild ( outerScaffold , sourceCodeDiv ) ;
769+
770+ outerScaffold . appendChild ( sourceCodeDiv ) ;
771+ outerScaffold . appendChild ( copyButton ) ;
759772 }
760773
761774 // insert example iframe
Original file line number Diff line number Diff line change @@ -282,7 +282,7 @@ details > summary > p:only-child {
282282}
283283
284284// codeCopy
285- div .sourceCode {
285+ div .code-copy-outer-scaffold {
286286 position : relative ;
287287}
288288
Original file line number Diff line number Diff line change @@ -877,7 +877,8 @@ pre.sourceCode {
877877 border : none ;
878878 }
879879 font-size : $code-block-font-size ;
880- overflow-y : auto !important ;
880+ overflow-y : visible !important ;
881+ // overflow-y: auto !important;
881882 @if $code-block-bg {
882883 padding : $code-block-bg-padding ;
883884 }
@@ -890,7 +891,8 @@ pre.sourceCode > code.sourceCode {
890891}
891892
892893div .sourceCode {
893- position : relative ;
894+ overflow-y : hidden ;
895+ // position: relative;
894896}
895897
896898.callout div .sourceCode {
You can’t perform that action at this time.
0 commit comments