set caret on mount as we usually do, so FF doesn't enter 2 newlines 🤯
This commit is contained in:
parent
98e033a529
commit
245f48a22c
2 changed files with 11 additions and 6 deletions
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
@ -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};});
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue