Skip to content

Commit 8f3bb40

Browse files
fix: handleNewLine function to properly add new line in desired location (#838)
* fix shift+enter in messageBox * lint
1 parent bcc7e95 commit 8f3bb40

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

packages/react/src/views/ChatInput/ChatInput.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ import useShowCommands from '../../hooks/useShowCommands';
3434
import useSearchMentionUser from '../../hooks/useSearchMentionUser';
3535
import formatSelection from '../../lib/formatSelection';
3636
import { parseEmoji } from '../../lib/emoji';
37-
import { Markdown } from '../Markdown';
3837

3938
const ChatInput = ({ scrollToBottom }) => {
4039
const { styleOverrides, classNames } = useComponentOverrides('ChatInput');
@@ -172,7 +171,15 @@ const ChatInput = ({ scrollToBottom }) => {
172171
};
173172

174173
const handleNewLine = (e, addLine = true) => {
175-
if (addLine) messageRef.current.value += '\n';
174+
if (addLine) {
175+
const { selectionStart, selectionEnd, value } = messageRef.current;
176+
messageRef.current.value = `${value.substring(
177+
0,
178+
selectionStart
179+
)}\n${value.substring(selectionEnd)}`;
180+
messageRef.current.selectionStart = messageRef.current.selectionEnd;
181+
messageRef.current.selectionEnd = selectionStart + 1;
182+
}
176183

177184
e.target.style.height = 'auto';
178185
if (e.target.scrollHeight <= 150) {

0 commit comments

Comments
 (0)