mirror of https://github.com/vector-im/riot-web
set caret on mount as we usually do, so FF doesn't enter 2 newlines 🤯
parent
98e033a529
commit
245f48a22c
|
@ -144,12 +144,7 @@ export default class MessageEditor extends React.Component {
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
this._updateEditorState();
|
this._updateEditorState();
|
||||||
const sel = document.getSelection();
|
setCaretPosition(this._editorRef, this.model, this.model.getPositionAtEnd());
|
||||||
const range = document.createRange();
|
|
||||||
range.selectNodeContents(this._editorRef);
|
|
||||||
range.collapse(false);
|
|
||||||
sel.removeAllRanges();
|
|
||||||
sel.addRange(range);
|
|
||||||
this._editorRef.focus();
|
this._editorRef.focus();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -61,6 +61,16 @@ export default class EditorModel {
|
||||||
return null;
|
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() {
|
serializeParts() {
|
||||||
return this._parts.map(({type, text}) => {return {type, text};});
|
return this._parts.map(({type, text}) => {return {type, text};});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue