Skip to content

Commit

Permalink
remove the placeholder text of and disable the default paragraph bloc…
Browse files Browse the repository at this point in the history
…k, in zoom out mode
  • Loading branch information
draganescu committed Dec 18, 2024
1 parent 3159fa2 commit bd9410e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
11 changes: 11 additions & 0 deletions packages/block-editor/src/store/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { PREFERENCES_DEFAULTS, SETTINGS_DEFAULTS } from './defaults';
import { insertAt, moveTo } from './array';
import { sectionRootClientIdKey } from './private-keys';
import { unlock } from '../lock-unlock';
import { getBlockName } from './selectors';

const { isContentBlock } = unlock( blocksPrivateApis );

Expand Down Expand Up @@ -2268,6 +2269,16 @@ function getDerivedBlockEditingModesForTree(
traverseBlockTree( state, treeClientId, ( block ) => {
const { clientId, name: blockName } = block;
if ( isZoomedOut || isNavMode ) {
if (
isZoomedOut &&
state.blocks.order.length === 1 &&
getBlockName( state.blocks.order[ 0 ] ) === 'core/paragraph' &&
state.blocks.order[ 0 ] === clientId
) {
derivedBlockEditingModes.set( clientId, 'disabled' );
return;
}

// If the root block is the section root set its editing mode to contentOnly.
if ( clientId === sectionRootClientId ) {
derivedBlockEditingModes.set( clientId, 'contentOnly' );
Expand Down
18 changes: 15 additions & 3 deletions packages/block-library/src/paragraph/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,16 @@ import {
useBlockProps,
useSettings,
useBlockEditingMode,
store as blockEditorStore,
} from '@wordpress/block-editor';
import { useSelect } from '@wordpress/data';
import { getBlockSupport } from '@wordpress/blocks';
import { formatLtr } from '@wordpress/icons';

/**
* Internal dependencies
*/
import { useOnEnter } from './use-enter';
import { unlock } from '../lock-unlock';

function ParagraphRTLControl( { direction, setDirection } ) {
return (
Expand Down Expand Up @@ -109,7 +111,11 @@ function ParagraphBlock( {
isSelected: isSingleSelected,
name,
} ) {
const { align, content, direction, dropCap, placeholder } = attributes;
const isZoomOut = useSelect( ( select ) =>
unlock( select( blockEditorStore ) ).isZoomOut()
);

const { align, content, direction, dropCap } = attributes;
const blockProps = useBlockProps( {
ref: useOnEnter( { clientId, content } ),
className: clsx( {
Expand All @@ -119,6 +125,12 @@ function ParagraphBlock( {
style: { direction },
} );
const blockEditingMode = useBlockEditingMode();
let { placeholder } = attributes;
if ( isZoomOut ) {
placeholder = '';
} else if ( ! placeholder ) {
placeholder = __( 'Type / to choose a block' );
}

return (
<>
Expand Down Expand Up @@ -170,7 +182,7 @@ function ParagraphBlock( {
: __( 'Block: Paragraph' )
}
data-empty={ RichText.isEmpty( content ) }
placeholder={ placeholder || __( 'Type / to choose a block' ) }
placeholder={ placeholder }
data-custom-placeholder={ placeholder ? true : undefined }
__unstableEmbedURLOnPaste
__unstableAllowPrefixTransformations
Expand Down

0 comments on commit bd9410e

Please sign in to comment.