From 8f3bb40f65f4dc46e87839ca56cf9bb8f9bb9415 Mon Sep 17 00:00:00 2001 From: Piyush <157290995+thepiyush-303@users.noreply.github.com> Date: Sat, 11 Jan 2025 22:10:47 +0530 Subject: [PATCH] fix: handleNewLine function to properly add new line in desired location (#838) * fix shift+enter in messageBox * lint --- packages/react/src/views/ChatInput/ChatInput.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/packages/react/src/views/ChatInput/ChatInput.js b/packages/react/src/views/ChatInput/ChatInput.js index aca2de0ac..33f40d7af 100644 --- a/packages/react/src/views/ChatInput/ChatInput.js +++ b/packages/react/src/views/ChatInput/ChatInput.js @@ -34,7 +34,6 @@ import useShowCommands from '../../hooks/useShowCommands'; import useSearchMentionUser from '../../hooks/useSearchMentionUser'; import formatSelection from '../../lib/formatSelection'; import { parseEmoji } from '../../lib/emoji'; -import { Markdown } from '../Markdown'; const ChatInput = ({ scrollToBottom }) => { const { styleOverrides, classNames } = useComponentOverrides('ChatInput'); @@ -172,7 +171,15 @@ const ChatInput = ({ scrollToBottom }) => { }; const handleNewLine = (e, addLine = true) => { - if (addLine) messageRef.current.value += '\n'; + if (addLine) { + const { selectionStart, selectionEnd, value } = messageRef.current; + messageRef.current.value = `${value.substring( + 0, + selectionStart + )}\n${value.substring(selectionEnd)}`; + messageRef.current.selectionStart = messageRef.current.selectionEnd; + messageRef.current.selectionEnd = selectionStart + 1; + } e.target.style.height = 'auto'; if (e.target.scrollHeight <= 150) {