From 8b4fd4c305a6effa8afbb37f46d76c34e40ddced Mon Sep 17 00:00:00 2001 From: Madhu Dollu Date: Fri, 18 Oct 2024 12:48:23 +0530 Subject: [PATCH] Fix zoom out not persisting while switching between editor and code editor (#65932) * reset zoomLevel on component unmount * conditionally reset zoom level * revert iframe changes and reset zoomLevel in the text-editor Co-authored-by: madhusudhand Co-authored-by: draganescu Co-authored-by: getdave Co-authored-by: youknowriad Co-authored-by: aaronrobertshaw Co-authored-by: yani- Co-authored-by: ironprogrammer Co-authored-by: simison Co-authored-by: PARTHVATALIYA --- packages/editor/src/components/text-editor/index.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/editor/src/components/text-editor/index.js b/packages/editor/src/components/text-editor/index.js index fa0688859b5a6..6997c66826a12 100644 --- a/packages/editor/src/components/text-editor/index.js +++ b/packages/editor/src/components/text-editor/index.js @@ -6,6 +6,7 @@ import { useDispatch, useSelect } from '@wordpress/data'; import { __ } from '@wordpress/i18n'; import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts'; import { useEffect, useRef } from '@wordpress/element'; +import { store as blockEditorStore } from '@wordpress/block-editor'; /** * Internal dependencies @@ -13,6 +14,7 @@ import { useEffect, useRef } from '@wordpress/element'; import { store as editorStore } from '../../store'; import PostTextEditor from '../post-text-editor'; import PostTitleRaw from '../post-title/post-title-raw'; +import { unlock } from '../../lock-unlock'; export default function TextEditor( { autoFocus = false } ) { const { switchEditorMode } = useDispatch( editorStore ); @@ -26,13 +28,20 @@ export default function TextEditor( { autoFocus = false } ) { }; }, [] ); + const { resetZoomLevel, __unstableSetEditorMode } = unlock( + useDispatch( blockEditorStore ) + ); + const titleRef = useRef(); useEffect( () => { + resetZoomLevel(); + __unstableSetEditorMode( 'edit' ); + if ( autoFocus ) { return; } titleRef?.current?.focus(); - }, [ autoFocus ] ); + }, [ autoFocus, resetZoomLevel, __unstableSetEditorMode ] ); return (