set caret on mount as we usually do, so FF doesn't enter 2 newlines 🤯

pull/21833/head
Bruno Windels 2019-05-16 18:39:20 +01:00
parent 98e033a529
commit 245f48a22c
2 changed files with 11 additions and 6 deletions

View File

@ -144,12 +144,7 @@ export default class MessageEditor extends React.Component {
componentDidMount() {
this._updateEditorState();
const sel = document.getSelection();
const range = document.createRange();
range.selectNodeContents(this._editorRef);
range.collapse(false);
sel.removeAllRanges();
sel.addRange(range);
setCaretPosition(this._editorRef, this.model, this.model.getPositionAtEnd());
this._editorRef.focus();
}

View File

@ -61,6 +61,16 @@ export default class EditorModel {
return null;
}
getPositionAtEnd() {
if (this._parts.length) {
const index = this._parts.length - 1;
const part = this._parts[index];
return new DocumentPosition(index, part.text.length);
} else {
return new DocumentPosition(0, 0);
}
}
serializeParts() {
return this._parts.map(({type, text}) => {return {type, text};});
}