From d6717c4799e30b297b0b0d8a2dc8c759681c4e99 Mon Sep 17 00:00:00 2001 From: ntsekouras Date: Tue, 26 Apr 2022 13:05:52 +0300 Subject: [PATCH] [RichText]: Ignore selection changes on non contentEditable nodes --- .../rich-text/src/component/use-input-and-selection.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/packages/rich-text/src/component/use-input-and-selection.js b/packages/rich-text/src/component/use-input-and-selection.js index 173a54dd463dd9..c1c36808d5996e 100644 --- a/packages/rich-text/src/component/use-input-and-selection.js +++ b/packages/rich-text/src/component/use-input-and-selection.js @@ -132,6 +132,13 @@ export function useInputAndSelection( props ) { onSelectionChange, } = propsRef.current; + // Check if the implementor disabled editing. `contentEditable` + // does disable input, but not text selection, so we must ignore + // selection changes. + if ( element.contentEditable !== 'true' ) { + return; + } + // If the selection changes where the active element is a parent of // the rich text instance (writing flow), call `onSelectionChange` // for the rich text instance that contains the start or end of the