From 741b13ab6f32c7a623dac640bfadfdd735094dbe Mon Sep 17 00:00:00 2001 From: Robin Date: Sun, 17 Apr 2022 09:45:34 -0400 Subject: [PATCH] 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. --- src/editor/caret.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/editor/caret.ts b/src/editor/caret.ts index b2b7846880..a4e4258ad6 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);