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): 完善列表与插件命令边界

zhangyongjiee76f7bb5f313
diff --git a/apps/desktop/src/renderer/__tests__/composerStructuredLists.test.ts b/apps/desktop/src/renderer/__tests__/composerStructuredLists.test.ts
index 2cc3e9a786..dca870c106 100644
--- a/apps/desktop/src/renderer/__tests__/composerStructuredLists.test.ts
+++ b/apps/desktop/src/renderer/__tests__/composerStructuredLists.test.ts
@@ -146,6 +146,11 @@ describe('composer structured list input rules', () => {
listType: 'orderedList',
attrs: { start: 3, marker: ')' },
},
+ {
+ typed: '10000000. ',
+ listType: 'orderedList',
+ attrs: { start: 10000000, marker: '.' },
+ },
{
typed: '2、',
listType: 'orderedList',
@@ -1184,6 +1189,40 @@ describe('composer structured list serialization', () => {
]);
});
+ it('keeps a pasted quote-like chip separate from a list quote chip', () => {
+ const editor = makeEditor({
+ type: 'doc',
+ content: [
+ {
+ type: 'bulletList',
+ content: [
+ {
+ type: 'listItem',
+ content: [
+ {
+ type: 'paragraph',
+ content: [
+ { type: COMPOSER_QUOTE_NODE_TYPE, attrs: { text: 'quoted' } },
+ {
+ type: 'pastedTextChip',
+ attrs: { text: '> pasted reply', display: '> pasted reply' },
+ },
+ ],
+ },
+ ],
+ },
+ ],
+ },
+ ],
+ });
+
+ expect(parseChatQuoteSegments(serializeEditorContent(editor).text)).toEqual([
+ { kind: 'text', text: '- ' },
+ { kind: 'quote', quote: { text: 'quoted' } },
+ { kind: 'text', text: ' > pasted reply' },
+ ]);
+ });
+
it('reuses a hard-break continuation line for a list quote chip', () => {
const editor = makeEditor({
type: 'doc',
@@ -1219,6 +1258,40 @@ describe('composer structured list serialization', () => {
]);
});
+ it('does not duplicate an indented break after a list quote chip', () => {
+ const editor = makeEditor({
+ type: 'doc',
+ content: [
+ {
+ type: 'bulletList',
+ content: [
+ {
+ type: 'listItem',
+ content: [
+ {
+ type: 'paragraph',
+ content: [
+ { type: COMPOSER_QUOTE_NODE_TYPE, attrs: { text: 'quoted' } },
+ { type: 'hardBreak' },
+ { type: 'text', text: 'after' },
+ ],
+ },
+ ],
+ },
+ ],
+ },
+ ],
+ });
+
+ const serialized = serializeEditorContent(editor).text;
+ expect(serialized).not.toContain('\n \n ');
+ expect(parseChatQuoteSegments(serialized)).toEqual([
+ { kind: 'text', text: '- ' },
+ { kind: 'quote', quote: { text: 'quoted' } },
+ { kind: 'text', text: ' after' },
+ ]);
+ });
+
it('preserves indentation on an empty nested list item', () => {
const editor = makeEditor({
type: 'doc',
diff --git a/apps/desktop/src/renderer/__tests__/ghostComposerPlacement.test.ts b/apps/desktop/src/renderer/__tests__/ghostComposerPlacement.test.ts
index ea44a84043..68c3f266fe 100644
--- a/apps/desktop/src/renderer/__tests__/ghostComposerPlacement.test.ts
+++ b/apps/desktop/src/renderer/__tests__/ghostComposerPlacement.test.ts
@@ -143,4 +143,54 @@ describe('placeGhostAtComposerStart', () => {
},
]);
});
+
+ it('does not replace a command that appears after leading list content', () => {
+ const editor = new Editor({
+ extensions: [
+ Document,
+ Paragraph,
+ Text,
+ ComposerListItem,
+ ComposerBulletList,
+ ComposerOrderedList,
+ MentionChipNode,
+ ],
+ content: {
+ type: 'doc',
+ content: [
+ {
+ type: 'bulletList',
+ content: [
+ {
+ type: 'listItem',
+ content: [
+ {
+ type: 'paragraph',
+ content: [{ type: 'text', text: 'first' }],
+ },
+ ],
+ },
+ ],
+ },
+ {
+ type: 'paragraph',
+ content: [{ type: 'text', text: '$old later text' }],
+ },
+ ],
+ },
+ });
+ editors.push(editor);
+
+ expect(placeGhostAtComposerStart(editor, ghost('mivo'), [ghost('mivo'), ghost('old')])).toBe(
+ true,
+ );
+ expect(editor.getJSON().content?.[0]).toEqual({
+ type: 'paragraph',
+ content: [{ type: 'text', text: '$mivo ' }],
+ });
+ expect(editor.getJSON().content?.[2]).toEqual({
+ type: 'paragraph',
+ content: [{ type: 'text', text: '$old later text' }],
+ });
+ });
});
diff --git a/apps/desktop/src/renderer/components/new-chat/ComposerListNodes.ts b/apps/desktop/src/renderer/components/new-chat/ComposerListNodes.ts
index 624ede279e..21733d967a 100644
--- a/apps/desktop/src/renderer/components/new-chat/ComposerListNodes.ts
+++ b/apps/desktop/src/renderer/components/new-chat/ComposerListNodes.ts
@@ -13,8 +13,8 @@ import { Selection, TextSelection } from '@tiptap/pm/state';
import type { EditorView } from '@tiptap/pm/view';
const BULLET_MARKER_RE = /^([-+*•])([ \t]+)$/;
-const ORDERED_MARKER_RE = /^([1-9]\d{0,6})([.)])([ \t]+)$/;
-const CJK_ORDERED_MARKER_RE = /^([1-9]\d{0,6})(、)$/;
+const ORDERED_MARKER_RE = /^([1-9]\d{0,7})([.)])([ \t]+)$/;
+const CJK_ORDERED_MARKER_RE = /^([1-9]\d{0,7})(、)$/;
type BulletMarker = '-' | '+' | '*' | '•';
type OrderedMarker = '.' | ')' | '、';
@@ -89,7 +89,7 @@ function plainListParagraphMarker(text: string): PlainListParagraphMarker | null
attrs: { marker: bullet[1], separator: bullet[2] },
};
}
- const ordered = text.match(/^([1-9]\d{0,6})([.)])([ \t]+)/);
+ const ordered = text.match(/^([1-9]\d{0,7})([.)])([ \t]+)/);
if (ordered) {
return {
kind: 'ordered',
@@ -97,7 +97,7 @@ function plainListParagraphMarker(text: string): PlainListParagraphMarker | null
attrs: { start: Number(ordered[1]), marker: ordered[2], separator: ordered[3] },
};
}
- const cjkOrdered = text.match(/^([1-9]\d{0,6})(、)([ \t]*)/);
+ const cjkOrdered = text.match(/^([1-9]\d{0,7})(、)([ \t]*)/);
if (cjkOrdered) {
return {
kind: 'ordered',
diff --git a/apps/desktop/src/renderer/components/new-chat/GhostCommandDecoration.ts b/apps/desktop/src/renderer/components/new-chat/GhostCommandDecoration.ts
index 7659e27afb..80ae9c565a 100644
--- a/apps/desktop/src/renderer/components/new-chat/GhostCommandDecoration.ts
+++ b/apps/desktop/src/renderer/components/new-chat/GhostCommandDecoration.ts
@@ -74,6 +74,10 @@ export function findGhostCommandMatch(
for (let pi = 0; pi < doc.childCount; pi++) {
const para = doc.child(pi);
if (para.type.name !== 'paragraph') {
+ // A command after a leading structured list is not a message-start
+ // command. Let the placement path insert the selected command before
+ // that list instead of replacing the later paragraph.
+ if (para.textContent.trim().length > 0) return null;
paraPos += para.nodeSize;
continue;
}
diff --git a/apps/desktop/src/renderer/components/new-chat/composerContentSerialization.ts b/apps/desktop/src/renderer/components/new-chat/composerContentSerialization.ts
index 204d4107fa..e65bcf0d5b 100644
--- a/apps/desktop/src/renderer/components/new-chat/composerContentSerialization.ts
+++ b/apps/desktop/src/renderer/components/new-chat/composerContentSerialization.ts
@@ -189,7 +189,20 @@ function serializeComposerDocument(
}
if (continuationAfterQuote !== null) {
- const childText = child.isText ? (child.text ?? '') : '';
+ if (child.type.name === 'hardBreak') {
+ // The quote parser needs a blank-line boundary, while the hard
+ // break itself still needs one indented continuation line. Emit
+ // both together so we do not leave an indentation-only line
+ // between two separately serialized breaks.
+ buffer += `\n\n${continuationIndent}`;
+ continuationAfterQuote = null;
+ return;
+ }
+ const childText = child.isText
+ ? (child.text ?? '')
+ : child.type.name === 'pastedTextChip'
+ ? String((child.attrs as PastedTextChipAttrs).text ?? '')
+ : '';
const alreadyIndented =
child.isText && childText.startsWith(continuationAfterQuote);
const textAfterIndent = alreadyIndented