⚡ perf(vscode): 代码阅读预览按卡片订阅状态:中文名、调用树棵数、单击高亮、问答一条消息只重画受影响的卡片和文字,新文档里内容没变的块沿用原来的对象不重画,没展开又没说过的块不画问答区
This commit is contained in:
1 parent
6e2c541558
commit
0ad4748cc6
27 files changed
+1359
-620
No files matched your search
@@ -1,7 +1,7 @@
|
||||
import type { ReactElement } from 'react'
|
||||
import type { MarkdownKind } from './markdown'
|
||||
import type { PreviewText } from './types'
|
||||
import { createContext, useContext, useMemo } from 'react'
|
||||
import { createContext, memo, useContext, useMemo } from 'react'
|
||||
import { cn } from '@/lib/utils'
|
||||
import { renderMarkdown } from './markdown'
|
||||
import { SegmentText } from './SegmentText'
|
||||
@@ -10,7 +10,7 @@ import { SegmentText } from './SegmentText'
|
||||
export const MarkdownKindContext = createContext<Exclude<MarkdownKind, 'answer'>>('comment')
|
||||
|
||||
/** 预览里的一段文字:着色的词按源码排版;Markdown 说明渲染成段落、列表、代码块。 */
|
||||
export function TextPreview({ text, className }: { text: PreviewText, className?: string }): ReactElement {
|
||||
export const TextPreview = memo(({ text, className }: { text: PreviewText, className?: string }): ReactElement => {
|
||||
const kind = useContext(MarkdownKindContext)
|
||||
if ('markdown' in text)
|
||||
return <MarkdownPreview html={renderMarkdown(text.markdown, kind)} className={className} />
|
||||
@@ -19,7 +19,8 @@ export function TextPreview({ text, className }: { text: PreviewText, className?
|
||||
<SegmentText segments={text} />
|
||||
</p>
|
||||
)
|
||||
}
|
||||
})
|
||||
TextPreview.displayName = 'TextPreview'
|
||||
|
||||
export function MarkdownPreview({ html, className }: { html: string, className?: string }): ReactElement {
|
||||
const content = useMemo(() => ({ __html: html }), [html])
|
||||
|
||||
Reference in new issue
Block a user