Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zoom Out: Disable zooming out when Distraction Free mode is activated #67028

Merged
merged 5 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
4 changes: 3 additions & 1 deletion packages/editor/src/components/header/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ function Header( {
showIconLabels,
hasFixedToolbar,
hasBlockSelection,
isDistractionFree,
} = useSelect( ( select ) => {
const { get: getPreference } = select( preferencesStore );
const {
Expand All @@ -80,6 +81,7 @@ function Header( {
hasFixedToolbar: getPreference( 'core', 'fixedToolbar' ),
hasBlockSelection:
!! select( blockEditorStore ).getBlockSelectionStart(),
isDistractionFree: getPreference( 'core', 'distractionFree' ),
};
}, [] );

Expand Down Expand Up @@ -167,7 +169,7 @@ function Header( {
forceIsAutosaveable={ forceIsDirty }
/>

{ canBeZoomedOut && isWideViewport && (
{ canBeZoomedOut && isWideViewport && ! isDistractionFree && (
<ZoomOutToggle disabled={ forceDisableBlockTools } />
) }

Expand Down
29 changes: 21 additions & 8 deletions packages/editor/src/components/more-menu/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
store as preferencesStore,
} from '@wordpress/preferences';
import { store as interfaceStore, ActionItem } from '@wordpress/interface';
import { store as blockEditorStore } from '@wordpress/block-editor';

/**
* Internal dependencies
Expand All @@ -25,21 +26,32 @@ import ModeSwitcher from '../mode-switcher';
import ToolsMoreMenuGroup from './tools-more-menu-group';
import ViewMoreMenuGroup from './view-more-menu-group';
import { store as editorStore } from '../../store';
import { unlock } from '../../lock-unlock';

export default function MoreMenu() {
const { openModal } = useDispatch( interfaceStore );
const { set: setPreference } = useDispatch( preferencesStore );
const { toggleDistractionFree } = useDispatch( editorStore );
const showIconLabels = useSelect(
( select ) =>
select( preferencesStore ).get( 'core', 'showIconLabels' ),
[]
);
const { resetZoomLevel } = unlock( useDispatch( blockEditorStore ) );
const { isZoomOut, showIconLabels } = useSelect( ( select ) => {
const { get: getPreference } = select( preferencesStore );

return {
showIconLabels: getPreference( 'core', 'showIconLabels' ),
isZoomOut: unlock( select( blockEditorStore ) ).isZoomOut(),
};
}, [] );

const turnOffDistractionFree = () => {
setPreference( 'core', 'distractionFree', false );
};

const handleZoomOut = () => {
if ( isZoomOut ) {
resetZoomLevel();
}
};

return (
<>
<DropdownMenu
Expand Down Expand Up @@ -80,11 +92,12 @@ export default function MoreMenu() {
label={ __( 'Distraction free' ) }
info={ __( 'Write with calmness' ) }
handleToggling={ false }
onToggle={ () =>
onToggle={ () => {
toggleDistractionFree( {
createNotice: false,
} )
}
} );
handleZoomOut();
} }
messageActivated={ __(
'Distraction free mode activated.'
) }
Expand Down
Loading