mirror of
https://github.com/nexu-io/open-design.git
synced 2026-05-31 19:04:39 +07:00
Merge 191f04ac4a into 729ce2b0cb
This commit is contained in:
commit
cfb59f51c9
1 changed files with 12 additions and 3 deletions
|
|
@ -1331,7 +1331,14 @@ export const ChatComposer = forwardRef<ChatComposerHandle, Props>(
|
|||
const prevEntries = pluginInsertedTokensRef.current;
|
||||
const prevActiveId = activePluginIdRef.current;
|
||||
|
||||
const result = replaceMentionWithText(`${inlineMentionToken(record.title)} `);
|
||||
// Capture mention state before async operation to prevent cursor
|
||||
// position issues if state changes during apply.
|
||||
const mentionSnapshot = mention;
|
||||
|
||||
const result = replaceMentionWithText(
|
||||
`${inlineMentionToken(record.title)} `,
|
||||
mentionSnapshot,
|
||||
);
|
||||
if (!result) return;
|
||||
// Capture the post-insert draft *snapshot* — the value the
|
||||
// composer is in immediately after our optimistic write.
|
||||
|
|
@ -1468,10 +1475,12 @@ export const ChatComposer = forwardRef<ChatComposerHandle, Props>(
|
|||
|
||||
function replaceMentionWithText(
|
||||
text: string,
|
||||
mentionSnapshot?: typeof mention,
|
||||
): { insertStart: number } | null {
|
||||
if (!mention) return null;
|
||||
const activeMention = mentionSnapshot ?? mention;
|
||||
if (!activeMention) return null;
|
||||
const ta = textareaRef.current;
|
||||
const cursor = mention.cursor;
|
||||
const cursor = activeMention.cursor;
|
||||
const before = draft.slice(0, cursor);
|
||||
const after = draft.slice(cursor);
|
||||
const replaced = before.replace(/(^|\s)@([^\s@]*)$/, `$1${text}`);
|
||||
|
|
|
|||
Loading…
Reference in a new issue