Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(desktop): 完善全选粘贴与空项复制
zhangyongjie374e37eee561
diff --git a/apps/desktop/src/renderer/__tests__/composerStructuredLists.test.ts b/apps/desktop/src/renderer/__tests__/composerStructuredLists.test.tsindex fc0da012a5..e755ba2816 100644--- a/apps/desktop/src/renderer/__tests__/composerStructuredLists.test.ts+++ b/apps/desktop/src/renderer/__tests__/composerStructuredLists.test.ts@@ -5,7 +5,7 @@ import Document from '@tiptap/extension-document';import Paragraph from '@tiptap/extension-paragraph';import Text from '@tiptap/extension-text';import HardBreak from '@tiptap/extension-hard-break';-import { TextSelection } from '@tiptap/pm/state';+import { AllSelection, TextSelection } from '@tiptap/pm/state';import {ComposerBulletList,@@ -784,6 +784,19 @@ describe('composer live plain-list promotion', () => {expect(editor.state.doc.firstChild?.type.name).toBe('paragraph');});+ it('recognizes a whole-document selection as a top-level block selection', () => {+ const editor = makeEditor({+ type: 'doc',+ content: [+ { type: 'paragraph', content: [{ type: 'text', text: 'first' }] },+ { type: 'paragraph', content: [{ type: 'text', text: 'second' }] },+ ],+ });+ editor.view.dispatch(editor.state.tr.setSelection(new AllSelection(editor.state.doc)));++ expect(isTopLevelBlockSelection(editor.view)).toBe(true);+ });+it('promotes a trailing bullet-glyph row inserted outside input rules', () => {const editor = makeEditor({type: 'doc',@@ -1487,6 +1500,41 @@ describe('composer structured list serialization', () => {expect(serializeEditorSlice(editor, slice)).toBe('2. eco');});+ it('keeps the visible ordinal when copying an empty ordered-list item', () => {+ const editor = makeEditor({+ type: 'doc',+ content: [+ {+ type: 'orderedList',+ attrs: { start: 1, marker: '.' },+ content: [+ {+ type: 'listItem',+ content: [{ type: 'paragraph', content: [{ type: 'text', text: 'first' }] }],+ },+ {+ type: 'listItem',+ content: [{ type: 'paragraph' }],+ },+ ],+ },+ ],+ });+ let emptyParagraphPosition = 0;+ editor.state.doc.descendants((node, position) => {+ if (node.type.name === 'paragraph' && node.content.size === 0) {+ emptyParagraphPosition = position;+ }+ });+ editor.commands.setTextSelection(emptyParagraphPosition + 1);+ const slice = editor.state.doc.slice(+ emptyParagraphPosition,+ emptyParagraphPosition + 1,+ );++ expect(serializeEditorSlice(editor, slice)).toBe('2. ');+ });+it('adjusts the nested ordered list that contains the copied selection start', () => {const editor = makeEditor({type: 'doc',diff --git a/apps/desktop/src/renderer/components/new-chat/ComposerListNodes.ts b/apps/desktop/src/renderer/components/new-chat/ComposerListNodes.tsindex d0d9304041..14efcc480c 100644--- a/apps/desktop/src/renderer/components/new-chat/ComposerListNodes.ts+++ b/apps/desktop/src/renderer/components/new-chat/ComposerListNodes.ts@@ -554,12 +554,19 @@ export function isTrailingEmptyTopLevelParagraph(view: EditorView): boolean {export function isTopLevelBlockSelection(view: EditorView): boolean {const { state } = view;const { $from, $to } = state.selection;- return (+ const spansTopLevelBlocks =!state.selection.empty &&$from.depth === 1 &&$to.depth === 1 &&$from.parentOffset === 0 &&$to.parentOffset === $to.parent.content.size+ if (spansTopLevelBlocks) return true;+ return (+ !state.selection.empty &&+ $from.depth === 0 &&+ $to.depth === 0 &&+ $from.pos === 0 &&+ $to.pos === state.doc.content.size);}diff --git a/apps/desktop/src/renderer/components/new-chat/composerContentSerialization.ts b/apps/desktop/src/renderer/components/new-chat/composerContentSerialization.tsindex 80f601803c..59f768f0d5 100644--- a/apps/desktop/src/renderer/components/new-chat/composerContentSerialization.ts+++ b/apps/desktop/src/renderer/components/new-chat/composerContentSerialization.ts@@ -454,9 +454,11 @@ export function serializeEditorSlice(editor: Editor | null, slice: Slice): strin}let replaced = state.tr.replace(0, state.doc.content.size, slice).doc;const sourceIndex = sourceListDepth === null ? null : $from.index(sourceListDepth);- const firstOrderedList = (() => {+ const findFirstOrderedList = (+ document: ProseMirrorNode,+ ): { node: ProseMirrorNode; position: number } | null => {let found: { node: ProseMirrorNode; position: number } | null = null;- replaced.descendants((node, position) => {+ document.descendants((node, position) => {if (found === null && node.type.name === 'orderedList') {found = { node, position };return false;@@ -464,7 +466,8 @@ export function serializeEditorSlice(editor: Editor | null, slice: Slice): strinreturn found === null;});return found;- })();+ };+ let firstOrderedList = findFirstOrderedList(replaced);// A text-only slice from inside a list item loses the enclosing list.// Rebuild the selected source items so plain-text copies keep their marker.@@ -478,6 +481,7 @@ export function serializeEditorSlice(editor: Editor | null, slice: Slice): strinstate.doc.content.size,new Slice(Fragment.from(copiedList), 0, 0),).doc;+ firstOrderedList = findFirstOrderedList(replaced);}}@@ -496,12 +500,16 @@ export function serializeEditorSlice(editor: Editor | null, slice: Slice): strin}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;+ let orderedListPosition: number | null = firstContentPosition === null+ ? firstOrderedList?.position ?? null+ : null;+ if (firstContentPosition !== null) {+ const $firstContent = replaced.resolve(firstContentPosition);+ 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);