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): 收紧插件命令起始匹配

zhangyongjie12e0619bcfa4
diff --git a/apps/desktop/src/renderer/__tests__/ghostComposerPlacement.test.ts b/apps/desktop/src/renderer/__tests__/ghostComposerPlacement.test.ts
index 68c3f266fe..dd78e8eb36 100644
--- a/apps/desktop/src/renderer/__tests__/ghostComposerPlacement.test.ts
+++ b/apps/desktop/src/renderer/__tests__/ghostComposerPlacement.test.ts
@@ -193,4 +193,41 @@ describe('placeGhostAtComposerStart', () => {
content: [{ type: 'text', text: '$old later text' }],
});
});
+
+ it('does not replace a command that appears after an empty structured list', () => {
+ const editor = new Editor({
+ extensions: [
+ Document,
+ Paragraph,
+ Text,
+ ComposerListItem,
+ ComposerBulletList,
+ ComposerOrderedList,
+ MentionChipNode,
+ ],
+ content: {
+ type: 'doc',
+ content: [
+ {
+ type: 'bulletList',
+ content: [{ type: 'listItem', content: [{ type: 'paragraph' }] }],
+ },
+ {
+ 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?.[1]?.type).toBe('bulletList');
+ });
});
diff --git a/apps/desktop/src/renderer/components/new-chat/GhostCommandDecoration.ts b/apps/desktop/src/renderer/components/new-chat/GhostCommandDecoration.ts
index 80ae9c565a..4dd4f09de9 100644
--- a/apps/desktop/src/renderer/components/new-chat/GhostCommandDecoration.ts
+++ b/apps/desktop/src/renderer/components/new-chat/GhostCommandDecoration.ts
@@ -77,9 +77,7 @@ export function findGhostCommandMatch(
// 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;
+ return null;
}
let childPos = paraPos + 1; // 段落内容起点
for (let ci = 0; ci < para.childCount; ci++) {
diff --git a/apps/desktop/src/renderer/components/new-chat/composerContentSerialization.ts b/apps/desktop/src/renderer/components/new-chat/composerContentSerialization.ts
index 96508d0ffd..80f601803c 100644
--- a/apps/desktop/src/renderer/components/new-chat/composerContentSerialization.ts
+++ b/apps/desktop/src/renderer/components/new-chat/composerContentSerialization.ts
@@ -429,8 +429,9 @@ export function serializeEditorContent(editor: Editor): SerializedComposerConten
/**
* Serialize a selected editor fragment for plain-text clipboard consumers.
- * Replacing an empty document with the open slice lets ProseMirror rebuild
- * list context around selections that begin or end inside a list item.
+ * Replacing an empty document with the open slice lets ProseMirror retain
+ * surrounding structure; ordered-list context is rebuilt below when an
+ * inline-only slice omits it.
*/
export function serializeEditorSlice(editor: Editor | null, slice: Slice): string {
if (!editor) {