⚡ perf(vscode): 代码阅读预览屏幕外的顶层块跳过样式、排版和绘制(content-visibility),没画过的按内容估的高度占位;跳到某一行、恢复滚动位置、跳到改动和定义前先把目标那一带照常排版再量,滚过去位置不变
This commit is contained in:
1 parent
ffb0f147e1
commit
8a5d3761fd
9 files changed
+201
-9
No files matched your search
@@ -13,6 +13,7 @@ import { BlockTools } from './BlockTools'
|
||||
import { CodeEditor } from './CodeEditor'
|
||||
import { DiffText } from './DiffText'
|
||||
import { removedTitle } from './diffView'
|
||||
import { estimatedHeight } from './itemHeight'
|
||||
import { KindIcon } from './kindIcons'
|
||||
import { PropertyGrid, PropertyItems, PropertyTable } from './PropertyGrid'
|
||||
import { chatOf, EMPTY_CHAT, sameChat, unfinished } from './qa'
|
||||
@@ -303,7 +304,7 @@ const BlockItem = memo(({ block, item }: { block: BlockView, item: boolean }): R
|
||||
<>
|
||||
{shape.run !== undefined && <UnchangedStrip count={shape.run} onOpen={() => tree.onOpenRun(block.id)} />}
|
||||
{shape.shown && (
|
||||
<Item item={item} line={block.startLine}>
|
||||
<Item item={item} line={block.startLine} height={item ? estimatedHeight(block, shape.open) : 0}>
|
||||
<BlockCard block={block} shape={shape} ask={ask} rewrite={rewriting} />
|
||||
{/* 输入框、展开状态跟着块的记号走,文档刷新块 id 变了也不丢 */}
|
||||
{qa && ask.chat && (
|
||||
@@ -344,11 +345,14 @@ const BlockItem = memo(({ block, item }: { block: BlockView, item: boolean }): R
|
||||
})
|
||||
BlockItem.displayName = 'BlockItem'
|
||||
|
||||
/** 顶层一块的外层(见 BlockTree 的 items);不套时原样 */
|
||||
function Item({ item, line, children }: { item: boolean, line: number, children: ReactNode }): ReactElement {
|
||||
/**
|
||||
* 顶层一块的外层(见 BlockTree 的 items);不套时原样。离视口远时浏览器跳过它里面的样式、排版和绘制(.cr-item 的 content-visibility),
|
||||
* 没画过时按估的高度(height,见 estimatedHeight)占位,画过一次就记住真实高度。
|
||||
*/
|
||||
function Item({ item, line, height, children }: { item: boolean, line: number, height: number, children: ReactNode }): ReactElement {
|
||||
if (!item)
|
||||
return <>{children}</>
|
||||
return <div className="cr-item flex flex-col gap-2" data-line={line}>{children}</div>
|
||||
return <div className="cr-item flex flex-col gap-2" data-line={line} style={{ containIntrinsicBlockSize: `auto ${height}px` }}>{children}</div>
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user