From d6cbf6f9e8d2173488978e8468f3472bd4ed1bfa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Lorber?= Date: Fri, 21 Nov 2025 19:19:55 +0100 Subject: [PATCH] fix(theme): Fix code block text selection copy on Firefox? (#11565) --- .../src/theme/CodeBlock/Line/index.tsx | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/packages/docusaurus-theme-classic/src/theme/CodeBlock/Line/index.tsx b/packages/docusaurus-theme-classic/src/theme/CodeBlock/Line/index.tsx index 80000b80d3..803c06466e 100644 --- a/packages/docusaurus-theme-classic/src/theme/CodeBlock/Line/index.tsx +++ b/packages/docusaurus-theme-classic/src/theme/CodeBlock/Line/index.tsx @@ -14,16 +14,23 @@ import styles from './styles.module.css'; type Token = Props['line'][number]; -// Replaces '\n' by '' -// Historical code, not sure why we even need this :/ +// This
; +} + +// Replaces single lines with '\n' by '' so that we don't end up with +// duplicate line breaks (the '\n' + the artificial
above) +// see also https://github.com/facebook/docusaurus/pull/11565 function fixLineBreak(line: Token[]) { const singleLineBreakToken = line.length === 1 && line[0]!.content === '\n' ? line[0] : undefined; - if (singleLineBreakToken) { return [{...singleLineBreakToken, content: ''}]; } - return line; } @@ -35,7 +42,6 @@ export default function CodeBlockLine({ getTokenProps, }: Props): ReactNode { const line = fixLineBreak(lineProp); - const lineProps = getLineProps({ line, className: clsx(classNames, showLineNumbers && styles.codeLine), @@ -51,7 +57,7 @@ export default function CodeBlockLine({ }); return ( - +
{showLineNumbers ? ( <> @@ -60,7 +66,7 @@ export default function CodeBlockLine({ ) : ( lineTokens )} -
-
+ +
); }