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): 保留列表引用与多行边界

zhangyongjie9044b4a2970f
diff --git a/apps/desktop/src/renderer/__tests__/composerStructuredLists.test.ts b/apps/desktop/src/renderer/__tests__/composerStructuredLists.test.ts
index 43825904a6..b6f962b3c9 100644
--- a/apps/desktop/src/renderer/__tests__/composerStructuredLists.test.ts
+++ b/apps/desktop/src/renderer/__tests__/composerStructuredLists.test.ts
@@ -19,6 +19,7 @@ import {
serializeEditorContent,
serializeEditorSlice,
} from '@/components/new-chat/composerContentSerialization';
+import { parseChatQuoteSegments } from '@/lib/chatQuotes';
import { COMPOSER_QUOTE_NODE_TYPE } from '@/lib/composerQuoteDocument';
const TestMentionChip = Node.create({
@@ -620,6 +621,26 @@ describe('composer live plain-list promotion', () => {
expect(serializeEditorContent(editor).text).toBe('3、 项目');
});
+ it('does not promote a multiline paragraph as one list item', () => {
+ const editor = makeEditor({
+ type: 'doc',
+ content: [
+ {
+ type: 'paragraph',
+ content: [
+ { type: 'text', text: '1. first' },
+ { type: 'hardBreak' },
+ { type: 'text', text: '2. second' },
+ ],
+ },
+ ],
+ });
+ selectDocumentEnd(editor);
+
+ expect(promoteTrailingPlainListParagraph(editor.view)).toBe(false);
+ expect(editor.state.doc.firstChild?.type.name).toBe('paragraph');
+ });
+
it('promotes a trailing bullet-glyph row inserted outside input rules', () => {
const editor = makeEditor({
type: 'doc',
@@ -780,9 +801,9 @@ describe('composer structured list serialization', () => {
{
type: 'paragraph',
content: [
- { type: 'text', text: 'before ' },
+ { type: 'text', text: 'before' },
{ type: COMPOSER_QUOTE_NODE_TYPE, attrs: { text: 'quoted' } },
- { type: 'text', text: ' after' },
+ { type: 'text', text: 'after' },
],
},
],
@@ -792,9 +813,15 @@ describe('composer structured list serialization', () => {
],
});
- expect(serializeEditorContent(editor).text).toBe(
- '- before > <!-- cindy-composer-quote -->\n > quoted after',
+ const serialized = serializeEditorContent(editor).text;
+ expect(serialized).toBe(
+ '- before\n > <!-- cindy-composer-quote -->\n > quoted\n after',
);
+ expect(parseChatQuoteSegments(serialized)).toEqual([
+ { kind: 'text', text: '- before' },
+ { kind: 'quote', quote: { text: 'quoted' } },
+ { kind: 'text', text: ' after' },
+ ]);
});
it('preserves nested markers and projects atom ranges into wire offsets', () => {
diff --git a/apps/desktop/src/renderer/components/new-chat/ComposerListNodes.ts b/apps/desktop/src/renderer/components/new-chat/ComposerListNodes.ts
index 9811d356a0..9da33c3b00 100644
--- a/apps/desktop/src/renderer/components/new-chat/ComposerListNodes.ts
+++ b/apps/desktop/src/renderer/components/new-chat/ComposerListNodes.ts
@@ -425,6 +425,12 @@ function getTrailingPlainListParagraph(view: EditorView): {
}
const paragraph = $from.parent;
+ let hasHardBreak = false;
+ paragraph.forEach((child) => {
+ if (child.type.name === 'hardBreak') hasHardBreak = true;
+ });
+ if (hasHardBreak) return null;
+
const text = paragraph.textBetween(0, paragraph.content.size, '\uFFFC', '\uFFFC');
const marker = plainListParagraphMarker(text);
const first = paragraph.firstChild;
diff --git a/apps/desktop/src/renderer/components/new-chat/composerContentSerialization.ts b/apps/desktop/src/renderer/components/new-chat/composerContentSerialization.ts
index 5484135331..ad39af0aeb 100644
--- a/apps/desktop/src/renderer/components/new-chat/composerContentSerialization.ts
+++ b/apps/desktop/src/renderer/components/new-chat/composerContentSerialization.ts
@@ -94,6 +94,7 @@ function serializeComposerDocument(
let bufferPastedTextRanges: PastedTextRange[] = [];
let bufferSlashCommandRanges: SlashCommandRange[] = [];
let emittedInlineSegment = false;
+ let continuationAfterQuote: string | null = null;
const flushText = (force = false) => {
if (!force && !buffer) return;
@@ -136,13 +137,15 @@ function serializeComposerDocument(
);
if (prefix) {
// A quote chip inside a list item is part of that item. Keeping it
- // in the current text block preserves the list marker instead of
- // emitting an empty item followed by a top-level quote block.
+ // in the current text block preserves the list marker. Put the
+ // encoded quote on its own continuation lines so history parsing
+ // can still recognize the private marker and source metadata.
const continuationPrefix = ' '.repeat(prefix.length);
const quoteLines = quoteText.split('\n');
- buffer += quoteLines
- .map((line, index) => (index === 0 ? line : `${continuationPrefix}${line}`))
- .join('\n');
+ buffer += `\n${quoteLines
+ .map((line) => `${continuationPrefix}${line}`)
+ .join('\n')}`;
+ continuationAfterQuote = continuationPrefix;
} else {
flushText();
blocks.push({ kind: 'quote', text: quoteText });
@@ -151,6 +154,11 @@ function serializeComposerDocument(
return;
}
+ if (continuationAfterQuote !== null) {
+ buffer += `\n${continuationAfterQuote}`;
+ continuationAfterQuote = null;
+ }
+
if (child.type.name === 'mentionChip') {
const attrs = child.attrs as MentionChipAttrs;
addMention(attrs);
diff --git a/packages/maker-shared/src/__tests__/chatQuotes.test.ts b/packages/maker-shared/src/__tests__/chatQuotes.test.ts
index a3e7dfc781..9fe154f269 100644
--- a/packages/maker-shared/src/__tests__/chatQuotes.test.ts
+++ b/packages/maker-shared/src/__tests__/chatQuotes.test.ts
@@ -104,6 +104,16 @@ describe('parseChatQuoteSegments', () => {
]);
});
+ it('parses explicitly marked quotes nested under list indentation', () => {
+ const content = '- before\n > <!-- cindy-composer-quote -->\n > quoted\n after';
+ expect(parseChatQuoteSegments(content)).toEqual([
+ { kind: 'text', text: '- before' },
+ { kind: 'quote', quote: { text: 'quoted' } },
+ { kind: 'text', text: ' after' },
+ ]);
+ expect(stripChatQuoteMarkerLines(content)).toBe('- before\n > quoted\n after');
+ });
+
it('keeps internal quote and prose blank lines', () => {
const content = `before\n\n${formatQuoteForSend({ text: 'a\n\nb' })}\n\nafter\n\nstill after`;
expect(parseChatQuoteSegments(content)).toEqual([
diff --git a/packages/maker-shared/src/chatQuotes.ts b/packages/maker-shared/src/chatQuotes.ts
index f9f0b38e7f..81466c99c5 100644
--- a/packages/maker-shared/src/chatQuotes.ts
+++ b/packages/maker-shared/src/chatQuotes.ts
@@ -54,7 +54,7 @@ const QUOTE_BLOCK_MARKER_LINE = `> ${QUOTE_BLOCK_MARKER}`;
export function stripChatQuoteMarkerLines(content: string): string {
return content
.split('\n')
- .filter((line) => line !== QUOTE_BLOCK_MARKER_LINE)
+ .filter((line) => line.trimStart() !== QUOTE_BLOCK_MARKER_LINE)
.join('\n');
}
@@ -186,7 +186,11 @@ export function parseChatQuoteSegments(
let index = 0;
while (index < lines.length) {
const line = lines[index];
- const marked = line === QUOTE_BLOCK_MARKER_LINE;
+ const markerIndent =
+ line.trimStart() === QUOTE_BLOCK_MARKER_LINE
+ ? line.slice(0, line.length - line.trimStart().length)
+ : null;
+ const marked = markerIndent !== null;
const legacyLeading = allowLegacyLeadingQuotes && line.startsWith('> ');
if (!marked && !legacyLeading) {
textLines.push(line);
@@ -203,12 +207,13 @@ export function parseChatQuoteSegments(
const quoteLines: string[] = [];
while (index < lines.length) {
const quoteLine = lines[index];
- if (quoteLine.startsWith('> ')) {
- quoteLines.push(quoteLine.slice(2));
+ const quotePrefix = `${markerIndent ?? ''}>`;
+ if (quoteLine.startsWith(`${quotePrefix} `)) {
+ quoteLines.push(quoteLine.slice(quotePrefix.length + 1));
index += 1;
continue;
}
- if (quoteLine === '>') {
+ if (quoteLine === quotePrefix) {
quoteLines.push('');
index += 1;
continue;