From 9d49a5bb731b8fde8b13c9edc9dd9b4e5de2f31f Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Thu, 1 Aug 2019 11:28:01 +0200 Subject: [PATCH] pass caret to history manager upon initial render otherwise caret is put at editor start when undoing last step --- src/components/views/elements/MessageEditor.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/components/views/elements/MessageEditor.js b/src/components/views/elements/MessageEditor.js index 2a2872b2f0..3d113d5223 100644 --- a/src/components/views/elements/MessageEditor.js +++ b/src/components/views/elements/MessageEditor.js @@ -315,9 +315,7 @@ export default class MessageEditor extends React.Component { componentDidMount() { this._createEditorModel(); // initial render of model - this._updateEditorState(); - // initial caret position - this._initializeCaret(); + this._updateEditorState(this._getInitialCaretPosition()); // attach input listener by hand so React doesn't proxy the events, // as the proxied event doesn't support inputType, which we need. this._editorRef.addEventListener("input", this._onInput, true); @@ -350,7 +348,7 @@ export default class MessageEditor extends React.Component { ); } - _initializeCaret() { + _getInitialCaretPosition() { const {editState} = this.props; let caretPosition; if (editState.hasEditorState()) { @@ -362,7 +360,7 @@ export default class MessageEditor extends React.Component { // otherwise, set it at the end caretPosition = this.model.getPositionAtEnd(); } - setCaretPosition(this._editorRef, this.model, caretPosition); + return caretPosition; } render() {