mirror of
https://github.com/vector-im/element-web.git
synced 2025-10-17 02:11:31 +02:00
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.
This commit is contained in:
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…
x
Reference in New Issue
Block a user