Skip to content

Commit

Permalink
Zoom Out: Disable zooming out when Distraction Free mode is activated (
Browse files Browse the repository at this point in the history
…WordPress#67028)


Co-authored-by: yogeshbhutkar <[email protected]>
Co-authored-by: Mamaduka <[email protected]>
Co-authored-by: t-hamano <[email protected]>
Co-authored-by: draganescu <[email protected]>
  • Loading branch information
5 people authored Nov 19, 2024
1 parent 1723c37 commit c772226
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 14 deletions.
3 changes: 2 additions & 1 deletion packages/editor/src/components/header/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,8 @@

& > .editor-header__toolbar .editor-document-tools__document-overview-toggle,
& > .editor-header__settings > .editor-preview-dropdown,
& > .editor-header__settings > .interface-pinned-items {
& > .editor-header__settings > .interface-pinned-items,
& > .editor-header__settings > .editor-zoom-out-toggle {
display: none;
}

Expand Down
39 changes: 26 additions & 13 deletions packages/editor/src/components/zoom-out-toggle/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,19 @@ import { isAppleOS } from '@wordpress/keycodes';
import { unlock } from '../../lock-unlock';

const ZoomOutToggle = ( { disabled } ) => {
const { isZoomOut, showIconLabels } = useSelect( ( select ) => ( {
isZoomOut: unlock( select( blockEditorStore ) ).isZoomOut(),
showIconLabels: select( preferencesStore ).get(
'core',
'showIconLabels'
),
} ) );
const { isZoomOut, showIconLabels, isDistractionFree } = useSelect(
( select ) => ( {
isZoomOut: unlock( select( blockEditorStore ) ).isZoomOut(),
showIconLabels: select( preferencesStore ).get(
'core',
'showIconLabels'
),
isDistractionFree: select( preferencesStore ).get(
'core',
'distractionFree'
),
} )
);

const { resetZoomLevel, setZoomLevel } = unlock(
useDispatch( blockEditorStore )
Expand All @@ -52,13 +58,19 @@ const ZoomOutToggle = ( { disabled } ) => {
};
}, [ registerShortcut, unregisterShortcut ] );

useShortcut( 'core/editor/zoom', () => {
if ( isZoomOut ) {
resetZoomLevel();
} else {
setZoomLevel( 'auto-scaled' );
useShortcut(
'core/editor/zoom',
() => {
if ( isZoomOut ) {
resetZoomLevel();
} else {
setZoomLevel( 'auto-scaled' );
}
},
{
isDisabled: isDistractionFree,
}
} );
);

const handleZoomOut = () => {
if ( isZoomOut ) {
Expand All @@ -78,6 +90,7 @@ const ZoomOutToggle = ( { disabled } ) => {
isPressed={ isZoomOut }
size="compact"
showTooltip={ ! showIconLabels }
className="editor-zoom-out-toggle"
/>
);
};
Expand Down
3 changes: 3 additions & 0 deletions packages/editor/src/store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -834,6 +834,9 @@ export const toggleDistractionFree =
.set( 'core', 'fixedToolbar', true );
dispatch.setIsInserterOpened( false );
dispatch.setIsListViewOpened( false );
unlock(
registry.dispatch( blockEditorStore )
).resetZoomLevel();
} );
}
registry.batch( () => {
Expand Down

0 comments on commit c772226

Please sign in to comment.