Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit 741b13a

Browse files
authored
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.
1 parent 2234f04 commit 741b13a

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

src/editor/caret.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ function setDocumentRangeSelection(editor: HTMLDivElement, model: EditorModel, r
4343
}
4444

4545
export function setCaretPosition(editor: HTMLDivElement, model: EditorModel, caretPosition: IPosition) {
46+
if (model.isEmpty) return; // selection can't possibly be wrong, so avoid a reflow
47+
4648
const range = document.createRange();
4749
const { node, offset } = getNodeAndOffsetForPosition(editor, model, caretPosition);
4850
range.setStart(node, offset);

0 commit comments

Comments
 (0)