From d53fa7ab92864d47805c9e7509d7bde951372f58 Mon Sep 17 00:00:00 2001 From: Kevin Chavez Date: Mon, 30 Mar 2020 15:18:45 -0700 Subject: [PATCH] Only extend selection if it has ranges in setDraftEditorSelection.js Summary: Needed for writing assistance. More correct than D20659377 IMO. Reviewed By: raedle Differential Revision: D20713362 fbshipit-source-id: 77b118ceb50eb50b385e0385c2cd07169512ddc4 --- src/component/selection/setDraftEditorSelection.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/component/selection/setDraftEditorSelection.js b/src/component/selection/setDraftEditorSelection.js index 969ee9cb47..f138100c77 100644 --- a/src/component/selection/setDraftEditorSelection.js +++ b/src/component/selection/setDraftEditorSelection.js @@ -261,7 +261,11 @@ function addFocusToSelection( // logging to catch bug that is being reported in t18110632 const nodeWasFocus = node === selection.focusNode; try { - selection.extend(node, offset); + // Fixes some reports of "InvalidStateError: Failed to execute 'extend' on + // 'Selection': This Selection object doesn't have any Ranges." + if (selection.rangeCount > 0) { + selection.extend(node, offset); + } } catch (e) { DraftJsDebugLogging.logSelectionStateFailure({ anonymizedDom: getAnonymizedEditorDOM(node, function(n) {