Skip to content

Commit

Permalink
Edit Mode: Prevent editable text selection on first click
Browse files Browse the repository at this point in the history
  • Loading branch information
youknowriad authored and draganescu committed Sep 30, 2024
1 parent 56f6deb commit a7f757e
Showing 1 changed file with 8 additions and 50 deletions.
58 changes: 8 additions & 50 deletions packages/block-editor/src/store/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -2801,35 +2801,18 @@ export const __unstableGetVisibleBlocks = createSelector(
);

export function __unstableHasActiveBlockOverlayActive( state, clientId ) {
// Prevent overlay on blocks with a non-default editing mode. If the mdoe is
// 'disabled' then the overlay is redundant since the block can't be
// selected. If the mode is 'contentOnly' then the overlay is redundant
// since there will be no controls to interact with once selected.
if ( getBlockEditingMode( state, clientId ) !== 'default' ) {
return false;
}

// If the block editing is locked, the block overlay is always active.
if ( ! canEditBlock( state, clientId ) ) {
return true;
}

const editorMode = __unstableGetEditorMode( state );

// In zoom-out mode, the block overlay is always active for section level blocks.
if ( editorMode === 'zoom-out' ) {
const sectionRootClientId = getSectionRootClientId( state );
if ( sectionRootClientId ) {
const sectionClientIds = getBlockOrder(
state,
sectionRootClientId
);
if ( sectionClientIds?.includes( clientId ) ) {
return true;
}
} else if ( clientId && ! getBlockRootClientId( state, clientId ) ) {
return true;
}
// Section blocks need to be selected first before being able to select their children.
if (
isSectionBlock( state, clientId ) &&
! isBlockSelected( state, clientId ) &&
! hasSelectedInnerBlock( state, clientId, true )
) {
return true;
}

// In navigation mode, the block overlay is active when the block is not
Expand Down Expand Up @@ -2913,33 +2896,8 @@ export const getBlockEditingMode = createRegistrySelector(
clientId = '';
}

// In zoom-out mode, override the behavior set by
// __unstableSetBlockEditingMode to only allow editing the top-level
// sections.
const editorMode = __unstableGetEditorMode( state );
if ( editorMode === 'zoom-out' ) {
const sectionRootClientId = getSectionRootClientId( state );

if ( clientId === '' /* ROOT_CONTAINER_CLIENT_ID */ ) {
return sectionRootClientId ? 'disabled' : 'contentOnly';
}
if ( clientId === sectionRootClientId ) {
return 'contentOnly';
}
const sectionsClientIds = getBlockOrder(
state,
sectionRootClientId
);

// Sections are always contentOnly.
if ( sectionsClientIds?.includes( clientId ) ) {
return 'contentOnly';
}

return 'disabled';
}

if ( editorMode === 'navigation' ) {
if ( [ 'navigation', 'zoom-out' ].includes( editorMode ) ) {
const sectionRootClientId = getSectionRootClientId( state );

// The root section is "default mode"
Expand Down

0 comments on commit a7f757e

Please sign in to comment.