diff --git a/src/components/room/RoomChatPanel.tsx b/src/components/room/RoomChatPanel.tsx index 972b477..94b18c4 100644 --- a/src/components/room/RoomChatPanel.tsx +++ b/src/components/room/RoomChatPanel.tsx @@ -131,8 +131,10 @@ const ChatInputArea = memo(function ChatInputArea({ const newCursorPos = startPos + 1 + category.length + 1; onDraftChangeRef.current(newValue); ms.setValue(newValue); - ms.setCursorOffset(newCursorPos); - ms.setShowMentionPopover(!!newValue.substring(0, newCursorPos).match(/@([^:@\s]*)(:([^\s]*))?$/)); + setTimeout(() => { + ms.setCursorOffset(newCursorPos); + ms.setShowMentionPopover(!!newValue.substring(0, newCursorPos).match(/@([^:@\s]*)(:([^\s]*))?$/)); + }, 0); }, })); @@ -247,7 +249,8 @@ const ChatInputArea = memo(function ChatInputArea({ const newCursorPos = startPos + 1 + category.length + 1; onDraftChangeRef.current(newValue); ms.setValue(newValue); - ms.setCursorOffset(newCursorPos); + // Defer cursor update until after DOM has flushed the new mention value + setTimeout(() => ms.setCursorOffset(newCursorPos), 0); }} suggestions={ms.suggestions} selectedIndex={ms.selectedIndex}