add emoji to the caret position (#1253)

This commit is contained in:
Meisam 2021-07-24 19:25:40 +02:00 committed by GitHub
parent 93f682d526
commit 7526b5305c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -123,10 +123,14 @@ export default class ChatInput extends Component {
content = emoji.emoji; content = emoji.emoji;
} }
const newHTML = inputHTML + content; const position = getCaretPosition(this.formMessageInput.current);
const newHTML = inputHTML.substring(0, position) +
content +
inputHTML.substring(position);
const charsLeft = this.calculateCurrentBytesLeft(newHTML); const charsLeft = this.calculateCurrentBytesLeft(newHTML);
this.setState({ this.setState({
inputHTML: inputHTML + content, inputHTML: newHTML,
inputCharsLeft: charsLeft, inputCharsLeft: charsLeft,
}); });
// a hacky way add focus back into input field // a hacky way add focus back into input field