From cff38b083afa7bf8b8320060db1169542e4c80c9 Mon Sep 17 00:00:00 2001 From: Robin Townsend Date: Sat, 16 Apr 2022 21:30:38 -0400 Subject: [PATCH] Avoid a reflow when setting caret position on an empty composer This saves an extra ~12 ms on each room switch, because we can. --- src/editor/caret.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/editor/caret.ts b/src/editor/caret.ts index b2b7846880f..a4e4258ad6f 100644 --- a/src/editor/caret.ts +++ b/src/editor/caret.ts @@ -43,6 +43,8 @@ function setDocumentRangeSelection(editor: HTMLDivElement, model: EditorModel, r } 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 { node, offset } = getNodeAndOffsetForPosition(editor, model, caretPosition); range.setStart(node, offset);