From b93d5d5e8627b22447ad7dd3fbd22bdc5a764b28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=B7=E5=B8=83=E5=8A=B3=E5=A4=96=20=C2=B7=20=E8=B4=BE?= =?UTF-8?q?=E8=B4=B5?= <472285740@qq.com> Date: Wed, 16 Jul 2025 14:54:06 +0800 Subject: [PATCH] fix(core): apply insert in same position not refresh (#13210) ## Summary by CodeRabbit * **Refactor** * Improved the rendering process for block inserts, resulting in more efficient and streamlined updates when viewing block differences. No changes to user-facing features or behaviors. --- .../blocksuite/ai/widgets/block-diff/block.ts | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/packages/frontend/core/src/blocksuite/ai/widgets/block-diff/block.ts b/packages/frontend/core/src/blocksuite/ai/widgets/block-diff/block.ts index c0987028c0..4654ce6065 100644 --- a/packages/frontend/core/src/blocksuite/ai/widgets/block-diff/block.ts +++ b/packages/frontend/core/src/blocksuite/ai/widgets/block-diff/block.ts @@ -2,6 +2,7 @@ import { WidgetComponent, WidgetViewExtension } from '@blocksuite/affine/std'; import { ThemeProvider } from '@blocksuite/affine-shared/services'; import { unsafeCSSVarV2 } from '@blocksuite/affine-shared/theme'; import { css, html, nothing, type TemplateResult } from 'lit'; +import { repeat } from 'lit/directives/repeat.js'; import { literal, unsafeStatic } from 'lit/static-html.js'; import { BlockDiffProvider } from '../../services/block-diff'; @@ -91,11 +92,13 @@ export class AffineBlockDiffWidgetForBlock extends WidgetComponent { } private _renderInsert(from: string, blocks: Block[]) { - return blocks - .map((block, offset) => { + return html`${repeat( + blocks, + block => block.id, + (block, offset) => { const diffId = `insert-${block.id}-${offset}`; return this.diffService.isRejected('insert', `${from}:${offset}`) - ? null + ? nothing : html`
`; - }) - .filter(Boolean) as TemplateResult[]; + } + )}`; } private _renderUpdate(blockId: string, content: string) { @@ -189,11 +192,12 @@ export class AffineBlockDiffWidgetForBlock extends WidgetComponent { return nothing; } - const { deletes, inserts, updates } = service.getDiff(); + const diffMap = service.getDiff(); + const { deletes, inserts, updates } = diffMap; let deleteDiff: TemplateResult | symbol = nothing; let updateDiff: TemplateResult | symbol = nothing; - let insertDiff: TemplateResult[] | symbol = nothing; + let insertDiff: TemplateResult | symbol = nothing; if (deletes.includes(attached)) { deleteDiff = this._renderDelete(attached);