Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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