From e9ef3c50c82e6304cd2a332269ad666725169c6d Mon Sep 17 00:00:00 2001 From: DarkSky <25152247+darkskygit@users.noreply.github.com> Date: Fri, 15 May 2026 20:18:22 +0800 Subject: [PATCH] fix(editor): transcript note will create useless docs (#14976) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fix #13520 #### PR Dependency Tree * **PR #14976** 👈 This tree was auto-generated by [Charcoal](https://github.com/danerwilliams/charcoal) ## Summary by CodeRabbit * **Tests** * Added comprehensive test coverage for markdown insertion functionality to verify that existing document metadata remains unchanged when importing markdown content into workspace documents. * **Chores** * Optimized internal markdown-to-snapshot conversion process to use a more direct and efficient conversion approach. [![Review Change Stack](https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg)](https://app.coderabbit.ai/change-stack/toeverything/AFFiNE/pull/14976) --- .../blocksuite/utils/markdown-utils.spec.ts | 34 +++++++++++++++++++ .../src/blocksuite/utils/markdown-utils.ts | 25 ++------------ 2 files changed, 36 insertions(+), 23 deletions(-) create mode 100644 packages/frontend/core/src/blocksuite/utils/markdown-utils.spec.ts diff --git a/packages/frontend/core/src/blocksuite/utils/markdown-utils.spec.ts b/packages/frontend/core/src/blocksuite/utils/markdown-utils.spec.ts new file mode 100644 index 0000000000000..ea3c60eda2efb --- /dev/null +++ b/packages/frontend/core/src/blocksuite/utils/markdown-utils.spec.ts @@ -0,0 +1,34 @@ +import 'fake-indexeddb/auto'; + +import { getStoreManager } from '@affine/core/blocksuite/manager/store'; +import { Text } from '@blocksuite/affine/store'; +import { TestWorkspace } from '@blocksuite/affine/store/test'; +import { describe, expect, test } from 'vitest'; + +import { insertFromMarkdown } from './markdown-utils'; + +const extensions = getStoreManager().config.init().value.get('store'); + +describe('markdown-utils', () => { + test('insertFromMarkdown does not create docs in the target workspace', async () => { + const collection = new TestWorkspace({ id: 'test' }); + collection.meta.initialize(); + + const store = collection.createDoc('page0').getStore({ extensions }); + store.load(); + const rootId = store.addBlock('affine:page', { + title: new Text(''), + }); + const noteId = store.addBlock('affine:note', {}, rootId); + + await insertFromMarkdown( + undefined, + ['- Summary item', '## Decisions', '- Ship it'].join('\n'), + store, + noteId, + 0 + ); + + expect(collection.meta.docMetas.map(meta => meta.id)).toEqual(['page0']); + }); +}); diff --git a/packages/frontend/core/src/blocksuite/utils/markdown-utils.ts b/packages/frontend/core/src/blocksuite/utils/markdown-utils.ts index 464a8285279f0..a87f9c8779478 100644 --- a/packages/frontend/core/src/blocksuite/utils/markdown-utils.ts +++ b/packages/frontend/core/src/blocksuite/utils/markdown-utils.ts @@ -153,31 +153,10 @@ export const markdownToSnapshot = async ( pageId: store.id, }; - const page = await markdownAdapter.toDoc(payload); - - if (page) { - const pageSnapshot = transformer.docToSnapshot(page); - if (pageSnapshot) { - const snapshot: SliceSnapshot = { - type: 'slice', - content: [ - pageSnapshot.blocks.children.find( - b => b.flavour === 'affine:note' - ) as BlockSnapshot, - ], - workspaceId: payload.workspaceId, - pageId: payload.pageId, - }; - - return { - snapshot, - transformer, - }; - } - } + const snapshot = await markdownAdapter.toSliceSnapshot(payload); return { - snapshot: null, + snapshot, transformer, }; };