From 32b3d55ab8252cd0b44febd530246d88ad4372f6 Mon Sep 17 00:00:00 2001 From: Max Franke Date: Mon, 30 May 2022 17:53:41 -0300 Subject: [PATCH] feat(message-form): send emoji at caret position --- .../ui/components/chat/message-form/component.jsx | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/bigbluebutton-html5/imports/ui/components/chat/message-form/component.jsx b/bigbluebutton-html5/imports/ui/components/chat/message-form/component.jsx index a6537f43f1..5ea6e2e191 100755 --- a/bigbluebutton-html5/imports/ui/components/chat/message-form/component.jsx +++ b/bigbluebutton-html5/imports/ui/components/chat/message-form/component.jsx @@ -271,7 +271,18 @@ class MessageForm extends PureComponent { handleEmojiSelect(emojiObject) { const { message } = this.state; - this.setState({ message: message + emojiObject.native }); + const cursor = this.textarea.selectionStart; + + this.setState( + { + message: message.slice(0, cursor) + + emojiObject.native + + message.slice(cursor), + }, + ); + + const newCursor = cursor + emojiObject.native.length; + setTimeout(() => this.textarea.setSelectionRange(newCursor, newCursor), 10); } renderEmojiPicker() {