Skip to content

Commit

Permalink
Fix zoom out not persisting while switching between editor and code e…
Browse files Browse the repository at this point in the history
…ditor (#65932)

* reset zoomLevel on component unmount

* conditionally reset zoom level

* revert iframe changes and reset zoomLevel in the text-editor

Co-authored-by: madhusudhand <[email protected]>
Co-authored-by: draganescu <[email protected]>
Co-authored-by: getdave <[email protected]>
Co-authored-by: youknowriad <[email protected]>
Co-authored-by: aaronrobertshaw <[email protected]>
Co-authored-by: yani- <[email protected]>
Co-authored-by: ironprogrammer <[email protected]>
Co-authored-by: simison <[email protected]>
Co-authored-by: PARTHVATALIYA <[email protected]>
  • Loading branch information
10 people authored and gutenbergplugin committed Oct 18, 2024
1 parent 2bf589b commit 55f9895
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion packages/editor/src/components/text-editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ 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
*/
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 );
Expand All @@ -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 (
<div className="editor-text-editor">
Expand Down

0 comments on commit 55f9895

Please sign in to comment.