mirror of https://github.com/vector-im/riot-web
Avoid a reflow when setting caret position on an empty composer (#8348)
This saves an extra ~12 ms on each room switch, because we can.pull/28217/head
parent
2234f04332
commit
741b13ab6f
|
@ -43,6 +43,8 @@ function setDocumentRangeSelection(editor: HTMLDivElement, model: EditorModel, r
|
||||||
}
|
}
|
||||||
|
|
||||||
export function setCaretPosition(editor: HTMLDivElement, model: EditorModel, caretPosition: IPosition) {
|
export function setCaretPosition(editor: HTMLDivElement, model: EditorModel, caretPosition: IPosition) {
|
||||||
|
if (model.isEmpty) return; // selection can't possibly be wrong, so avoid a reflow
|
||||||
|
|
||||||
const range = document.createRange();
|
const range = document.createRange();
|
||||||
const { node, offset } = getNodeAndOffsetForPosition(editor, model, caretPosition);
|
const { node, offset } = getNodeAndOffsetForPosition(editor, model, caretPosition);
|
||||||
range.setStart(node, offset);
|
range.setStart(node, offset);
|
||||||
|
|
Loading…
Reference in New Issue