From b10555819489c5836229cd57dee40a7f837a8929 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ella=20van=C2=A0Durpe?= Date: Wed, 12 May 2021 23:30:21 +0300 Subject: [PATCH] Fixes --- packages/rich-text/src/component/index.js | 4 +++- .../src/component/use-input-and-selection.js | 12 +----------- 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/packages/rich-text/src/component/index.js b/packages/rich-text/src/component/index.js index 155fc206fd4ed..d258b8b33ca96 100644 --- a/packages/rich-text/src/component/index.js +++ b/packages/rich-text/src/component/index.js @@ -1,7 +1,7 @@ /** * WordPress dependencies */ -import { useRef, useLayoutEffect } from '@wordpress/element'; +import { useRef, useLayoutEffect, useReducer } from '@wordpress/element'; import { useMergeRefs, useRefEffect } from '@wordpress/compose'; /** @@ -36,6 +36,7 @@ export function useRichText( { __unstableBeforeSerialize, __unstableAddInvisibleFormats, } ) { + const [ , forceRender ] = useReducer( () => ( {} ) ); const ref = useRef(); function createRecord() { @@ -129,6 +130,7 @@ export function useRichText( { __unstableFormats: formats, __unstableText: text, } ); + forceRender(); } function applyFromProps( { domOnly } = {} ) { 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 a224317f85e4f..7f011f6ecb73a 100644 --- a/packages/rich-text/src/component/use-input-and-selection.js +++ b/packages/rich-text/src/component/use-input-and-selection.js @@ -80,10 +80,6 @@ export function useInputAndSelection( props ) { inputType = event.inputType; } - if ( ! inputType && event && event.nativeEvent ) { - inputType = event.nativeEvent.inputType; - } - const { record, applyRecord, @@ -228,12 +224,7 @@ export function useInputAndSelection( props ) { } function onFocus() { - const { - record, - isSelected, - onSelectionChange, - setActiveFormats, - } = propsRef.current; + const { record, isSelected, onSelectionChange } = propsRef.current; if ( ! isSelected ) { // We know for certain that on focus, the old selection is invalid. @@ -248,7 +239,6 @@ export function useInputAndSelection( props ) { activeFormats: EMPTY_ACTIVE_FORMATS, }; onSelectionChange( index, index ); - setActiveFormats( EMPTY_ACTIVE_FORMATS ); } else { onSelectionChange( record.current.start, record.current.end ); }