diff --git a/packages/core/admin/admin/src/content-manager/components/Wysiwyg/Editor.js b/packages/core/admin/admin/src/content-manager/components/Wysiwyg/Editor.js index fa5e9db199..8ddc1fdda6 100644 --- a/packages/core/admin/admin/src/content-manager/components/Wysiwyg/Editor.js +++ b/packages/core/admin/admin/src/content-manager/components/Wysiwyg/Editor.js @@ -15,11 +15,9 @@ const Editor = ({ name, onChange, placeholder, - shouldSetValueAfterExpand, textareaRef, value, }) => { - const initialValueRef = useRef(value); const onChangeRef = useRef(onChange); useEffect(() => { @@ -33,10 +31,6 @@ const Editor = ({ readOnly: false, }); - if (initialValueRef.current) { - editorRef.current.setValue(initialValueRef.current); - } - CodeMirror.commands.newlineAndIndentContinueMarkdownList = newlineAndIndentContinueMarkdownList; editorRef.current.on('change', doc => { onChangeRef.current({ target: { name, value: doc.getValue(), type: 'wysiwyg' } }); @@ -44,10 +38,10 @@ const Editor = ({ }, [editorRef, textareaRef, name]); useEffect(() => { - if (shouldSetValueAfterExpand && value) { + if (value && !editorRef.current.state.focused) { editorRef.current.setValue(value); } - }, [editorRef, shouldSetValueAfterExpand, value]); + }, [editorRef, value]); useEffect(() => { if (isPreviewMode || disabled) { @@ -81,7 +75,6 @@ Editor.defaultProps = { error: undefined, isPreviewMode: false, placeholder: '', - shouldSetValueAfterExpand: false, value: '', }; @@ -93,7 +86,6 @@ Editor.propTypes = { name: PropTypes.string.isRequired, onChange: PropTypes.func.isRequired, placeholder: PropTypes.string, - shouldSetValueAfterExpand: PropTypes.bool, textareaRef: PropTypes.shape({ current: PropTypes.any }).isRequired, value: PropTypes.string, }; diff --git a/packages/core/admin/admin/src/content-manager/components/Wysiwyg/index.js b/packages/core/admin/admin/src/content-manager/components/Wysiwyg/index.js index f84a0886fe..351aea13c7 100644 --- a/packages/core/admin/admin/src/content-manager/components/Wysiwyg/index.js +++ b/packages/core/admin/admin/src/content-manager/components/Wysiwyg/index.js @@ -67,7 +67,6 @@ const Wysiwyg = ({ const [isPreviewMode, setIsPreviewMode] = useState(false); const [mediaLibVisible, setMediaLibVisible] = useState(false); const [isExpandMode, setIsExpandMode] = useState(false); - const [shouldSetValueAfterExpand, setShouldSetValueAfterExpand] = useState(false); const handleToggleMediaLib = () => setMediaLibVisible(prev => !prev); const handleTogglePopover = () => setVisiblePopover(prev => !prev); @@ -120,13 +119,8 @@ const Wysiwyg = ({ insertImage(currentEditorRef, files); }; - const handleToggleExpand = collapse => { + const handleToggleExpand = () => { setIsExpandMode(prev => !prev); - setShouldSetValueAfterExpand(false); - - if (collapse === 'collapse' && value) { - setShouldSetValueAfterExpand(true); - } }; return ( @@ -153,7 +147,6 @@ const Wysiwyg = ({ name={name} onChange={onChange} placeholder={formattedPlaceholder} - shouldSetValueAfterExpand={shouldSetValueAfterExpand} textareaRef={textareaRef} value={value} />