From a3379ef17d8a0665d3cb36a6872ac03706da029b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=87=BF=E9=A9=B9-=E4=BC=AF=E4=B9=90?= Date: Thu, 27 Aug 2026 12:53:47 +0800 Subject: [PATCH] fix(conversation): insert the selection popup text at the composer caret (#425) appendToDraft always spliced at the end of the draft. The conversation service exposes no caret API, so probe the live composer textarea selection from the DOM (value-sync guarded) and splice at that position with whitespace-aware joins; an unknown or stale caret falls back to appending. The explorer @-reference shares this path, so it inserts at the caret too. --- src/client/conversation-draft.ts | 84 +++++++++++++++++++-- tests/conversation-draft.spec.ts | 122 +++++++++++++++++++++++++++++++ 2 files changed, 200 insertions(+), 6 deletions(-) create mode 100644 tests/conversation-draft.spec.ts diff --git a/src/client/conversation-draft.ts b/src/client/conversation-draft.ts index 9047054..f6c8fef 100644 --- a/src/client/conversation-draft.ts +++ b/src/client/conversation-draft.ts @@ -1,16 +1,88 @@ /** - * Append text to the current session's composer draft through the + * Insert text into the current session's composer draft through the * conversation service — the shared path behind the explorer's @-reference * button and the viewer selection popup. The service is resolved lazily * through `ctx.get` (the inject-free read the app's own plugins use); a * missing service or scope degrades to a logged no-op, never a crash. + * + * Insert position (fixes upstream issue #425): the draft store only exposes + * the whole string (`getSnapshot().draft` + `setDraft(text)`) — there is no + * caret API on the conversation service. The composer's `