Skip to content

Commit

Permalink
Editor: Handle zoom out state via the 'switchEditorMode' action (Word…
Browse files Browse the repository at this point in the history
…Press#66262)


Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>
Co-authored-by: youknowriad <youknowriad@git.wordpress.org>
  • Loading branch information
3 people authored Oct 21, 2024
1 parent 88de21b commit a416596
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 11 deletions.
11 changes: 1 addition & 10 deletions packages/editor/src/components/text-editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,13 @@ 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 @@ -28,20 +26,13 @@ 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, resetZoomLevel, __unstableSetEditorMode ] );
}, [ autoFocus ] );

return (
<div className="editor-text-editor">
Expand Down
4 changes: 3 additions & 1 deletion packages/editor/src/store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -883,9 +883,11 @@ export const switchEditorMode =
( { dispatch, registry } ) => {
registry.dispatch( preferencesStore ).set( 'core', 'editorMode', mode );

// Unselect blocks when we switch to a non visual mode.
if ( mode !== 'visual' ) {
// Unselect blocks when we switch to a non visual mode.
registry.dispatch( blockEditorStore ).clearSelectedBlock();
// Exit zoom out state when switching to a non visual mode.
unlock( registry.dispatch( blockEditorStore ) ).resetZoomLevel();
}

if ( mode === 'visual' ) {
Expand Down

0 comments on commit a416596

Please sign in to comment.