Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(desktop): 完善围栏与多行列表边界
zhangyongjied100d3ce86be
diff --git a/apps/desktop/src/renderer/__tests__/composerListDocument.test.ts b/apps/desktop/src/renderer/__tests__/composerListDocument.test.tsindex 09041fa3ac..65bc8879c2 100644--- a/apps/desktop/src/renderer/__tests__/composerListDocument.test.ts+++ b/apps/desktop/src/renderer/__tests__/composerListDocument.test.ts@@ -37,6 +37,15 @@ describe('composer list document normalization', () => {expect(document.content?.[0]?.content).toHaveLength(2);});+ it('restores a generated eight-digit ordered continuation as one list', () => {+ const document = plainTextToComposerDocument('9999999. first\n10000000. second');+ expect(document.content?.[0]).toMatchObject({+ type: 'orderedList',+ attrs: { start: 9999999, marker: '.' },+ });+ expect(document.content?.[0]?.content).toHaveLength(2);+ });+it('keeps surrounding paragraphs and task bodies intact', () => {expect(plainTextToComposerDocument('intro\n- [ ] todo\n- [x] done\noutro')).toEqual({type: 'doc',diff --git a/apps/desktop/src/renderer/__tests__/composerStructuredLists.test.ts b/apps/desktop/src/renderer/__tests__/composerStructuredLists.test.tsindex c4a80f0497..2cc3e9a786 100644--- a/apps/desktop/src/renderer/__tests__/composerStructuredLists.test.ts+++ b/apps/desktop/src/renderer/__tests__/composerStructuredLists.test.ts@@ -311,6 +311,22 @@ describe('composer structured list input rules', () => {expect(editor.state.doc.firstChild?.type.name).toBe('paragraph');expect(editor.state.doc.firstChild?.textContent).toBe('```1. ');});++ it('keeps ordinary list markers literal after a preceding open fence', () => {+ const editor = makeEditor({+ type: 'doc',+ content: [+ { type: 'paragraph', content: [{ type: 'text', text: '```' }] },+ { type: 'paragraph' },+ ],+ });+ selectDocumentEnd(editor);++ typeThroughInputRules(editor, '1. ');++ expect(editor.state.doc.lastChild?.type.name).toBe('paragraph');+ expect(editor.state.doc.lastChild?.textContent).toBe('1. ');+ });});describe('composer structured list keyboard commands', () => {@@ -970,6 +986,44 @@ describe('composer structured list serialization', () => {expect(serializeEditorContent(editor).text).toBe('- first\n second');});+ it('indents multiline pasted-text chips inside a list item', () => {+ const editor = makeEditor({+ type: 'doc',+ content: [+ {+ type: 'bulletList',+ content: [+ {+ type: 'listItem',+ content: [+ {+ type: 'paragraph',+ content: [+ { type: 'text', text: 'prefix ' },+ {+ type: 'pastedTextChip',+ attrs: { text: 'first\nsecond', display: 'Pasted text (2 lines)' },+ },+ ],+ },+ ],+ },+ ],+ },+ ],+ });++ const serialized = serializeEditorContent(editor);+ expect(serialized.text).toBe('- prefix first\n second');+ expect(serialized.pastedTextRanges).toEqual([+ {+ start: '- prefix '.length,+ end: serialized.text.length,+ display: 'Pasted text (2 lines)',+ },+ ]);+ });+it('keeps a dragged quote inside its list item', () => {const editor = makeEditor({type: 'doc',@@ -1130,6 +1184,41 @@ describe('composer structured list serialization', () => {]);});+ it('reuses a hard-break continuation line for a list quote chip', () => {+ const editor = makeEditor({+ type: 'doc',+ content: [+ {+ type: 'bulletList',+ content: [+ {+ type: 'listItem',+ content: [+ {+ type: 'paragraph',+ content: [+ { type: 'text', text: 'before' },+ { type: 'hardBreak' },+ { type: COMPOSER_QUOTE_NODE_TYPE, attrs: { text: 'quoted' } },+ ],+ },+ ],+ },+ ],+ },+ ],+ });++ const serialized = serializeEditorContent(editor).text;+ expect(serialized).toBe(+ '- before\n > <!-- cindy-composer-quote -->\n > quoted',+ );+ expect(parseChatQuoteSegments(serialized)).toEqual([+ { kind: 'text', text: '- before' },+ { kind: 'quote', quote: { text: 'quoted' } },+ ]);+ });+it('preserves indentation on an empty nested list item', () => {const editor = makeEditor({type: 'doc',@@ -1267,6 +1356,68 @@ describe('composer structured list serialization', () => {expect(serializeEditorSlice(editor, slice)).toBe('2. eco');});+ it('adjusts the nested ordered list that contains the copied selection start', () => {+ const editor = makeEditor({+ type: 'doc',+ content: [+ {+ type: 'orderedList',+ attrs: { start: 1, marker: '.' },+ content: [+ {+ type: 'listItem',+ content: [+ { type: 'paragraph', content: [{ type: 'text', text: 'outer-first' }] },+ {+ type: 'orderedList',+ attrs: { start: 5, marker: '.' },+ content: [+ {+ type: 'listItem',+ content: [+ { type: 'paragraph', content: [{ type: 'text', text: 'nested-first' }] },+ ],+ },+ {+ type: 'listItem',+ content: [+ { type: 'paragraph', content: [{ type: 'text', text: 'nested-second' }] },+ ],+ },+ ],+ },+ ],+ },+ {+ type: 'listItem',+ content: [+ { type: 'paragraph', content: [{ type: 'text', text: 'outer-second' }] },+ ],+ },+ ],+ },+ ],+ });+ let nestedSecondPosition = 0;+ let outerSecondPosition = 0;+ editor.state.doc.descendants((node, position) => {+ if (node.isText && node.text === 'nested-second') nestedSecondPosition = position;+ if (node.isText && node.text === 'outer-second') outerSecondPosition = position;+ });+ editor.commands.setTextSelection({+ from: nestedSecondPosition,+ to: outerSecondPosition + 'outer-second'.length,+ });+ const slice = editor.state.doc.slice(+ editor.state.selection.from,+ editor.state.selection.to,+ );++ const copied = serializeEditorSlice(editor, slice);+ expect(copied).toContain('6. nested-second');+ expect(copied).not.toContain('1. nested-second');+ });+it('preserves nested markers and projects atom ranges into wire offsets', () => {const href = 'cindy://session/session-a?message=message-a';const editor = makeEditor({diff --git a/apps/desktop/src/renderer/components/new-chat/ComposerListNodes.ts b/apps/desktop/src/renderer/components/new-chat/ComposerListNodes.tsindex 5fdfac531b..624ede279e 100644--- a/apps/desktop/src/renderer/components/new-chat/ComposerListNodes.ts+++ b/apps/desktop/src/renderer/components/new-chat/ComposerListNodes.ts@@ -164,6 +164,25 @@ function hardBreakListInputRule(});}+function fenceAwareWrappingInputRule(+ config: Parameters<typeof wrappingInputRule>[0],+): InputRule {+ const rule = wrappingInputRule(config);+ return new InputRule({+ find: rule.find,+ handler: (props) => {+ const $markerStart = props.state.doc.resolve(props.range.from);+ if (+ $markerStart.depth === 1 &&+ documentFenceStateBefore(props.state.doc, $markerStart.before(1))+ ) {+ return null;+ }+ return rule.handler(props);+ },+ });+}+const listItemConfig: NodeConfig = {name: 'listItem',group: 'block',@@ -211,7 +230,7 @@ export const ComposerBulletList = Node.create({},addInputRules() {return [- wrappingInputRule({+ fenceAwareWrappingInputRule({find: BULLET_MARKER_RE,type: this.type,joinPredicate: (match, before) =>@@ -302,13 +321,13 @@ export const ComposerOrderedList = Node.create({},addInputRules() {return [- wrappingInputRule({+ fenceAwareWrappingInputRule({find: ORDERED_MARKER_RE,type: this.type,joinPredicate: canJoinOrderedList,getAttributes: orderedAttrs,}),- wrappingInputRule({+ fenceAwareWrappingInputRule({find: CJK_ORDERED_MARKER_RE,type: this.type,joinPredicate: canJoinOrderedList,diff --git a/apps/desktop/src/renderer/components/new-chat/composerContentSerialization.ts b/apps/desktop/src/renderer/components/new-chat/composerContentSerialization.tsindex 282dce0135..204d4107fa 100644--- a/apps/desktop/src/renderer/components/new-chat/composerContentSerialization.ts+++ b/apps/desktop/src/renderer/components/new-chat/composerContentSerialization.ts@@ -38,7 +38,7 @@ export interface SerializedComposerContent {type OrderedMarker = '.' | ')' | '、';const EMPTY_LIST_ITEM_MARKER_RE =- /(?:^|\n)[ \t]*(?:[1-9]\d{0,6}[.)][ \t]+|[1-9]\d{0,6}、[ \t]*|[-+*•][ \t]+)$/;+ /(?:^|\n)[ \t]*(?:[1-9]\d{0,7}[.)][ \t]+|[1-9]\d{0,7}、[ \t]*|[-+*•][ \t]+)$/;const TAB_SIZE = 4;@@ -56,8 +56,8 @@ function expandedIndentWidth(text: string): number {function literalListContinuationPrefix(text: string): string | null {const match =- text.match(/^([ \t]+)(?:[-+*•]|[1-9]\d{0,6}[.)])([ \t]+)/) ??- text.match(/^([ \t]+)[1-9]\d{0,6}、[ \t]*/);+ text.match(/^([ \t]+)(?:[-+*•]|[1-9]\d{0,7}[.)])([ \t]+)/) ??+ text.match(/^([ \t]+)[1-9]\d{0,7}、[ \t]*/);if (!match) return null;return ' '.repeat(expandedIndentWidth(match[0]));}@@ -169,9 +169,15 @@ function serializeComposerDocument(const continuationPrefix =continuationIndent || ' '.repeat(expandedIndentWidth(prefix));const quoteLines = quoteText.split('\n');- const quoteSeparator = continuationAfterQuote === null ? '' : '\n';- buffer += `${quoteSeparator}\n${quoteLines- .map((line) => `${continuationPrefix}${line}`)+ const hasContinuationLine =+ continuationAfterQuote === null &&+ buffer.endsWith(`\n${continuationPrefix}`);+ const quoteSeparator =+ continuationAfterQuote !== null ? '\n\n' : hasContinuationLine ? '' : '\n';+ buffer += `${quoteSeparator}${quoteLines+ .map((line, index) =>+ hasContinuationLine && index === 0 ? line : `${continuationPrefix}${line}`,+ ).join('\n')}`;continuationAfterQuote = continuationPrefix;} else {@@ -266,7 +272,9 @@ function serializeComposerDocument(if (child.type.name === 'pastedTextChip') {const attrs = child.attrs as PastedTextChipAttrs;const start = buffer.length;- buffer += attrs.text;+ buffer += continuationIndent+ ? attrs.text.replace(/\n/g, `\n${continuationIndent}`)+ : attrs.text;bufferPastedTextRanges.push({ start, end: buffer.length, display: attrs.display });return;}@@ -466,14 +474,21 @@ export function serializeEditorSlice(editor: Editor | null, slice: Slice): strin? Number(sourceList.attrs.start) + sourceIndex: null;if (copiedStart !== null) {- let orderedListPosition: number | null = null;+ let firstContentPosition: number | null = null;replaced.descendants((node, position) => {- if (orderedListPosition === null && node.type.name === 'orderedList') {- orderedListPosition = position;+ if (firstContentPosition === null && (node.isText || node.isAtom)) {+ firstContentPosition = position;return false;}- return orderedListPosition === null;+ return firstContentPosition === null;});+ const $firstContent = replaced.resolve(firstContentPosition ?? 0);+ let orderedListPosition: number | null = null;+ for (let depth = $firstContent.depth; depth > 0; depth -= 1) {+ if ($firstContent.node(depth).type.name !== 'orderedList') continue;+ orderedListPosition = $firstContent.before(depth);+ break;+ }if (orderedListPosition !== null) {const node = replaced.nodeAt(orderedListPosition);if (node) {diff --git a/apps/desktop/src/renderer/lib/__tests__/composerListContinuation.test.ts b/apps/desktop/src/renderer/lib/__tests__/composerListContinuation.test.tsindex 982085b818..d6914d7794 100644--- a/apps/desktop/src/renderer/lib/__tests__/composerListContinuation.test.ts+++ b/apps/desktop/src/renderer/lib/__tests__/composerListContinuation.test.ts@@ -18,6 +18,13 @@ describe('computeListContinuation', () => {});});+ it('八位数序号正常接续', () => {+ expect(computeListContinuation('10000000. item')).toEqual({+ action: 'continue',+ insert: '10000001. ',+ });+ });+it('保留分隔符后的多余空白', () => {expect(computeListContinuation('3. foo')).toEqual({ action: 'continue', insert: '4. ' });});diff --git a/apps/desktop/src/renderer/lib/composerListContinuation.ts b/apps/desktop/src/renderer/lib/composerListContinuation.tsindex e08109f9de..0b570eaf86 100644--- a/apps/desktop/src/renderer/lib/composerListContinuation.ts+++ b/apps/desktop/src/renderer/lib/composerListContinuation.ts@@ -23,9 +23,9 @@ export interface ListPrefixMatch {// checkbox 允许行在 `]` 处截止(`(\s+|$)`),这样 "- [ ]" 也能识别成空项退出。const CHECKBOX_RE = /^(\s*)([-+*])(\s+)\[[ xX]\](\s+|$)/;const BULLET_RE = /^(\s*)([-+*•])(\s+)/;-const ORDERED_RE = /^(\s*)(\d{1,7})([.)])(\s+)/;+const ORDERED_RE = /^(\s*)(\d{1,8})([.)])(\s+)/;// 中文顿号序号(`1、`)不要求后随空格,符合中文输入习惯。-const ORDERED_CJK_RE = /^(\s*)(\d{1,7})(、)(\s*)/;+const ORDERED_CJK_RE = /^(\s*)(\d{1,8})(、)(\s*)/;const QUOTE_RE = /^(\s*)(>)(\s+)/;/**diff --git a/apps/desktop/src/renderer/lib/composerListDocument.ts b/apps/desktop/src/renderer/lib/composerListDocument.tsindex 6da2ce61da..682f347511 100644--- a/apps/desktop/src/renderer/lib/composerListDocument.ts+++ b/apps/desktop/src/renderer/lib/composerListDocument.ts@@ -17,7 +17,7 @@ interface ComposerLine {}const BULLET_RE = /^([-+*•])([ \t]+)/;-const ORDERED_RE = /^([1-9]\d{0,6})([.)、])([ \t]*)/;+const ORDERED_RE = /^([1-9]\d{0,7})([.)、])([ \t]*)/;function inlineNodeText(node: JSONContent): string {if (node.type === 'text') return node.text ?? '';diff --git a/apps/desktop/src/renderer/styles/globals.css b/apps/desktop/src/renderer/styles/globals.cssindex a05318e176..73f90496ac 100644--- a/apps/desktop/src/renderer/styles/globals.css+++ b/apps/desktop/src/renderer/styles/globals.css@@ -372,6 +372,9 @@ html:lang(ko) {[data-chat-input-root] .ProseMirror ol[data-marker-digits='7'] {--composer-list-padding: 5.2em;}+[data-chat-input-root] .ProseMirror ol[data-marker-digits='8'] {+ --composer-list-padding: 5.8em;+}[data-chat-input-root] .ProseMirror ul {list-style-type: disc;}