From b212f9eaea7c12efb255830f45edb41a2addb5b6 Mon Sep 17 00:00:00 2001 From: Zihua Li Date: Thu, 24 Feb 2022 16:17:00 +0800 Subject: [PATCH] Avoid fetching selections when possible --- core/selection.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/core/selection.js b/core/selection.js index b099fad6e4..b1203e39b2 100644 --- a/core/selection.js +++ b/core/selection.js @@ -194,6 +194,12 @@ class Selection { } getRange() { + const root = this.scroll.domNode; + if ('isConnected' in root && !root.isConnected) { + // document.getSelection() forces layout on Blink, so we trend to + // not calling it. + return [null, null]; + } const normalized = this.getNativeRange(); if (normalized == null) return [null, null]; const range = this.normalizedToRange(normalized);