mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2025-12-22 08:40:08 +08:00
fix(CodePreview): revert to absolute positioning (#7980)
* fix(CodePreview): revert to absolute positioning * fix: add min width to codeblockview
This commit is contained in:
parent
9a81c400ab
commit
a93cab6b43
@ -164,19 +164,11 @@ const CodePreview = ({ children, language, setTools }: CodePreviewProps) => {
|
||||
}}>
|
||||
<div
|
||||
style={{
|
||||
/*
|
||||
* FIXME: @tanstack/react-virtual 使用绝对定位,但是会导致
|
||||
* 有气泡样式 `self-end` 并且气泡中只有代码块时整个代码块收缩
|
||||
* 到最小宽度(目前应该是工具栏的宽度)。改为相对定位可以保证宽
|
||||
* 度足够,目前没有发现其他副作用。
|
||||
* 如果发现破坏虚拟列表功能,或者将来有更好的解决方案,再调整。
|
||||
*/
|
||||
position: 'relative',
|
||||
position: 'absolute',
|
||||
top: 0,
|
||||
left: 0,
|
||||
width: '100%',
|
||||
transform: `translateY(${virtualItems[0]?.start ?? 0}px)`,
|
||||
willChange: 'transform'
|
||||
transform: `translateY(${virtualItems[0]?.start ?? 0}px)`
|
||||
}}>
|
||||
{virtualizer.getVirtualItems().map((virtualItem) => (
|
||||
<div key={virtualItem.key} data-index={virtualItem.index} ref={virtualizer.measureElement}>
|
||||
|
||||
@ -246,6 +246,11 @@ export const CodeBlockView: React.FC<Props> = memo(({ children, language, onSave
|
||||
const CodeBlockWrapper = styled.div<{ $isInSpecialView: boolean }>`
|
||||
position: relative;
|
||||
width: 100%;
|
||||
/* FIXME: 最小宽度用于解决两个问题。
|
||||
* 一是 CodePreview 在气泡样式下的用户消息中无法撑开气泡,
|
||||
* 二是 代码块内容过少时 toolbar 会和 title 重叠。
|
||||
*/
|
||||
min-width: 45ch;
|
||||
|
||||
.code-toolbar {
|
||||
background-color: ${(props) => (props.$isInSpecialView ? 'transparent' : 'var(--color-background-mute)')};
|
||||
|
||||
Loading…
Reference in New Issue
Block a user