Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(desktop): 保持围栏段落结构

zhangyongjie0a0e7afe65ae
diff --git a/apps/desktop/src/renderer/__tests__/composerListDocument.test.ts b/apps/desktop/src/renderer/__tests__/composerListDocument.test.ts
index 2c19de3f62..70432ef361 100644
--- a/apps/desktop/src/renderer/__tests__/composerListDocument.test.ts
+++ b/apps/desktop/src/renderer/__tests__/composerListDocument.test.ts
@@ -231,6 +231,27 @@ describe('composer list document normalization', () => {
});
});
+ it('keeps multiline paragraphs intact while inside a fenced code block', () => {
+ const document = {
+ type: 'doc' as const,
+ content: [
+ { type: 'paragraph', content: [{ type: 'text', text: '```' }] },
+ {
+ type: 'paragraph',
+ content: [
+ { type: 'text', text: '1. literal' },
+ { type: 'hardBreak' },
+ { type: 'text', text: '2. literal' },
+ ],
+ },
+ { type: 'paragraph', content: [{ type: 'text', text: '```' }] },
+ ],
+ };
+
+ const normalized = normalizeComposerDocumentJSON(document);
+ expect(normalized.content?.[1]).toEqual(document.content[1]);
+ });
+
it('leaves existing structured content unchanged', () => {
const document = {
type: 'doc' as const,
diff --git a/apps/desktop/src/renderer/lib/composerListDocument.ts b/apps/desktop/src/renderer/lib/composerListDocument.ts
index 24bc6608a9..ff6c44e022 100644
--- a/apps/desktop/src/renderer/lib/composerListDocument.ts
+++ b/apps/desktop/src/renderer/lib/composerListDocument.ts
@@ -185,17 +185,19 @@ function paragraphToBlocks(
initialFence: FenceState | null,
): { blocks: JSONContent[]; fence: FenceState | null } {
const lines = splitParagraphLines(paragraph);
- if (!lines.some((line) => parseListMarker(line.text)) && !initialFence) {
- let fence: FenceState | null = initialFence;
- for (const line of lines) {
- const opening = fenceOpening(line.text);
- if (fence) {
- if (isFenceClosing(line.text, fence)) fence = null;
- } else if (opening) {
- fence = opening;
- }
+ let scannedFence: FenceState | null = initialFence;
+ let hasPromotableList = false;
+ for (const line of lines) {
+ if (scannedFence) {
+ if (isFenceClosing(line.text, scannedFence)) scannedFence = null;
+ continue;
}
- return { blocks: [paragraph], fence };
+ if (parseListMarker(line.text)) hasPromotableList = true;
+ const opening = fenceOpening(line.text);
+ if (opening) scannedFence = opening;
+ }
+ if (!hasPromotableList) {
+ return { blocks: [paragraph], fence: scannedFence };
}
const blocks: JSONContent[] = [];