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
Robin 2022-04-17 09:45:34 -04:00 committed by GitHub
parent 2234f04332
commit 741b13ab6f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 0 deletions

View File

@ -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);