fix(core): apply insert in same position not refresh (#13210)
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## 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. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
@@ -2,6 +2,7 @@ import { WidgetComponent, WidgetViewExtension } from '@blocksuite/affine/std';
|
|||||||
import { ThemeProvider } from '@blocksuite/affine-shared/services';
|
import { ThemeProvider } from '@blocksuite/affine-shared/services';
|
||||||
import { unsafeCSSVarV2 } from '@blocksuite/affine-shared/theme';
|
import { unsafeCSSVarV2 } from '@blocksuite/affine-shared/theme';
|
||||||
import { css, html, nothing, type TemplateResult } from 'lit';
|
import { css, html, nothing, type TemplateResult } from 'lit';
|
||||||
|
import { repeat } from 'lit/directives/repeat.js';
|
||||||
import { literal, unsafeStatic } from 'lit/static-html.js';
|
import { literal, unsafeStatic } from 'lit/static-html.js';
|
||||||
|
|
||||||
import { BlockDiffProvider } from '../../services/block-diff';
|
import { BlockDiffProvider } from '../../services/block-diff';
|
||||||
@@ -91,11 +92,13 @@ export class AffineBlockDiffWidgetForBlock extends WidgetComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private _renderInsert(from: string, blocks: Block[]) {
|
private _renderInsert(from: string, blocks: Block[]) {
|
||||||
return blocks
|
return html`${repeat(
|
||||||
.map((block, offset) => {
|
blocks,
|
||||||
|
block => block.id,
|
||||||
|
(block, offset) => {
|
||||||
const diffId = `insert-${block.id}-${offset}`;
|
const diffId = `insert-${block.id}-${offset}`;
|
||||||
return this.diffService.isRejected('insert', `${from}:${offset}`)
|
return this.diffService.isRejected('insert', `${from}:${offset}`)
|
||||||
? null
|
? nothing
|
||||||
: html`<div class="ai-block-diff insert" data-diff-id=${diffId}>
|
: html`<div class="ai-block-diff insert" data-diff-id=${diffId}>
|
||||||
<chat-content-rich-text
|
<chat-content-rich-text
|
||||||
.text=${block.content}
|
.text=${block.content}
|
||||||
@@ -120,8 +123,8 @@ export class AffineBlockDiffWidgetForBlock extends WidgetComponent {
|
|||||||
})}
|
})}
|
||||||
></ai-block-diff-options>
|
></ai-block-diff-options>
|
||||||
</div>`;
|
</div>`;
|
||||||
})
|
}
|
||||||
.filter(Boolean) as TemplateResult[];
|
)}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
private _renderUpdate(blockId: string, content: string) {
|
private _renderUpdate(blockId: string, content: string) {
|
||||||
@@ -189,11 +192,12 @@ export class AffineBlockDiffWidgetForBlock extends WidgetComponent {
|
|||||||
return nothing;
|
return nothing;
|
||||||
}
|
}
|
||||||
|
|
||||||
const { deletes, inserts, updates } = service.getDiff();
|
const diffMap = service.getDiff();
|
||||||
|
const { deletes, inserts, updates } = diffMap;
|
||||||
|
|
||||||
let deleteDiff: TemplateResult | symbol = nothing;
|
let deleteDiff: TemplateResult | symbol = nothing;
|
||||||
let updateDiff: TemplateResult | symbol = nothing;
|
let updateDiff: TemplateResult | symbol = nothing;
|
||||||
let insertDiff: TemplateResult[] | symbol = nothing;
|
let insertDiff: TemplateResult | symbol = nothing;
|
||||||
|
|
||||||
if (deletes.includes(attached)) {
|
if (deletes.includes(attached)) {
|
||||||
deleteDiff = this._renderDelete(attached);
|
deleteDiff = this._renderDelete(attached);
|
||||||
|
|||||||
Reference in New Issue
Block a user