From a31e54074fe2f9c7dbf1d5678072dccc800730f0 Mon Sep 17 00:00:00 2001 From: MadCcc <1075746765@qq.com> Date: Tue, 16 Jan 2024 20:32:05 +0800 Subject: [PATCH 1/5] fix: source code should wrap --- src/client/theme-default/builtins/SourceCode/index.less | 3 +++ src/client/theme-default/slots/SourceCodeEditor/index.less | 5 +++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/client/theme-default/builtins/SourceCode/index.less b/src/client/theme-default/builtins/SourceCode/index.less index 18b9387530..5234f9be85 100644 --- a/src/client/theme-default/builtins/SourceCode/index.less +++ b/src/client/theme-default/builtins/SourceCode/index.less @@ -32,6 +32,9 @@ line-height: 1.58; direction: ltr; background: transparent; + white-space: pre-wrap; + word-break: keep-all; + overflow-wrap: break-word; // remove shadow from coy theme &::before, diff --git a/src/client/theme-default/slots/SourceCodeEditor/index.less b/src/client/theme-default/slots/SourceCodeEditor/index.less index 0385bf44a4..bf84b31575 100644 --- a/src/client/theme-default/slots/SourceCodeEditor/index.less +++ b/src/client/theme-default/slots/SourceCodeEditor/index.less @@ -13,8 +13,6 @@ height: 100%; color: transparent; caret-color: @c-text; - overflow-wrap: normal; - white-space: pre; box-sizing: border-box; background: transparent; opacity: 1; @@ -24,6 +22,9 @@ overflow: hidden; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; + white-space: pre-wrap; + word-break: keep-all; + overflow-wrap: break-word; @{dark-selector} & { caret-color: @c-text-dark; From 4a6d8b10e8b07e37852c1d4dee873ee5ec145ea8 Mon Sep 17 00:00:00 2001 From: MadCcc <1075746765@qq.com> Date: Tue, 23 Jan 2024 22:06:30 +0800 Subject: [PATCH 2/5] fix: code scroll --- .../builtins/SourceCode/index.less | 23 ++++- .../builtins/SourceCode/index.tsx | 92 +++++++++++-------- .../slots/SourceCodeEditor/index.less | 28 ++++-- .../slots/SourceCodeEditor/index.tsx | 66 +++++++------ 4 files changed, 125 insertions(+), 84 deletions(-) diff --git a/src/client/theme-default/builtins/SourceCode/index.less b/src/client/theme-default/builtins/SourceCode/index.less index 5234f9be85..f306186090 100644 --- a/src/client/theme-default/builtins/SourceCode/index.less +++ b/src/client/theme-default/builtins/SourceCode/index.less @@ -25,16 +25,31 @@ border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; - > pre.prism-code { + &-scroll-container { + overflow: auto; + width: 100%; + height: 100%; + } + + &-scroll-content { + position: relative; + width: max-content; + height: max-content; + min-width: 100%; + min-height: 100%; + } + + > pre.prism-code, + &-scroll-content > pre.prism-code { margin: 0; padding: 18px 24px; font-size: 14px; line-height: 1.58; direction: ltr; background: transparent; - white-space: pre-wrap; - word-break: keep-all; - overflow-wrap: break-word; + overflow: visible; + width: max-content; + position: relative; // remove shadow from coy theme &::before, diff --git a/src/client/theme-default/builtins/SourceCode/index.tsx b/src/client/theme-default/builtins/SourceCode/index.tsx index ed6b4af4ed..efd907dad5 100644 --- a/src/client/theme-default/builtins/SourceCode/index.tsx +++ b/src/client/theme-default/builtins/SourceCode/index.tsx @@ -27,6 +27,7 @@ interface SourceCodeProps { lang: Language; highlightLines?: number[]; extra?: ReactNode; + textarea?: ReactNode; } const SourceCode: FC = (props) => { @@ -44,6 +45,48 @@ const SourceCode: FC = (props) => { } }, [lang, children]); + const code = ( + + {({ className, style, tokens, getLineProps, getTokenProps }) => ( +
+          {tokens.map((line, i) => (
+            
+ {themeConfig.showLineNum && ( + {i + 1} + )} +
+ {line.map((token, key) => ( + // getTokenProps 返回值包含 key + // eslint-disable-next-line react/jsx-key + + ))} +
+
+ ))} +
+ )} +
+ ); + return (
= (props) => { {isCopied ? : } - - {({ className, style, tokens, getLineProps, getTokenProps }) => ( -
-            {tokens.map((line, i) => (
-              
- {themeConfig.showLineNum && ( - {i + 1} - )} -
- {line.map((token, key) => ( - // getTokenProps 返回值包含 key - // eslint-disable-next-line react/jsx-key - - ))} -
-
- ))} -
- )} -
+ {props.textarea ? ( +
+
+ {code} + {props.textarea} +
+
+ ) : ( + code + )} {props.extra}
); diff --git a/src/client/theme-default/slots/SourceCodeEditor/index.less b/src/client/theme-default/slots/SourceCodeEditor/index.less index bf84b31575..d6058adaf6 100644 --- a/src/client/theme-default/slots/SourceCodeEditor/index.less +++ b/src/client/theme-default/slots/SourceCodeEditor/index.less @@ -13,6 +13,8 @@ height: 100%; color: transparent; caret-color: @c-text; + overflow-wrap: normal; + white-space: pre; box-sizing: border-box; background: transparent; opacity: 1; @@ -22,20 +24,13 @@ overflow: hidden; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; - white-space: pre-wrap; - word-break: keep-all; - overflow-wrap: break-word; @{dark-selector} & { caret-color: @c-text-dark; } &:focus { - box-shadow: 0 0 0 1px lighten(@c-primary, 20%) inset; - @{dark-selector} & { - box-shadow: 0 0 0 1px darken(@c-primary-dark, 20%) inset; - // for firefox because its selection color is not translucent when color-scheme is dark &::selection { background-color: fade(@c-primary-dark, 30%); @@ -43,4 +38,23 @@ } } } + + &:focus-within { + &::after { + content: ''; + position: absolute; + z-index: 0; + top: 0; + left: 0; + width: 100%; + height: 100%; + border-bottom-left-radius: 3px; + border-bottom-right-radius: 3px; + box-shadow: 0 0 0 1px @c-primary inset; + + @{dark-selector} & { + box-shadow: 0 0 0 1px @c-primary-dark inset; + } + } + } } diff --git a/src/client/theme-default/slots/SourceCodeEditor/index.tsx b/src/client/theme-default/slots/SourceCodeEditor/index.tsx index 4fbb023121..da7af47cbe 100644 --- a/src/client/theme-default/slots/SourceCodeEditor/index.tsx +++ b/src/client/theme-default/slots/SourceCodeEditor/index.tsx @@ -51,45 +51,43 @@ const SourceCodeEditor: FC = (props) => {
-