fix(frontend): skip tracking effect update when caret is at end of text
Root cause: after onCategoryEnter sets value="@ai:", the MentionInput sync effect sets innerHTML with the new content. The browser caret may be at position 2 (not moved from the user's perspective), but prevCursorRef was 4. The tracking effect read DOM caret=2 and overwrote ms.setCursorOffset(4) → cursor jumped to position 2. Fix: skip tracking effect update when: - count (DOM caret) is at end of text (ms.value.length), AND - prevCursorRef was also at end of text This means the caret hasn't actually moved from the user's POV (just positioned by the browser after innerHTML), so don't update state.
This commit is contained in:
parent
126ffda4fe
commit
4330325bfc
@ -104,8 +104,13 @@ const ChatInputArea = memo(function ChatInputArea({
|
||||
count += node.length;
|
||||
}
|
||||
if (count !== prevCursorRef.current) {
|
||||
prevCursorRef.current = count;
|
||||
ms.setCursorOffset(count);
|
||||
// Skip update when caret is at end of text (programmatic value change
|
||||
// that already positioned the caret — the caret hasn't moved from the
|
||||
// user's perspective). Only update on real user-initiated cursor movement.
|
||||
if (count !== ms.value.length || prevCursorRef.current !== ms.value.length) {
|
||||
prevCursorRef.current = count;
|
||||
ms.setCursorOffset(count);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user