Skip to content

Commit

Permalink
Fix slash inserter for widgets screen (#33161)
Browse files Browse the repository at this point in the history
* Revert "Fix insertion point displaying when there are no inserter items (#32576)"

This reverts commit 80ab980.

* Avoid setting insertion point within locked templates
  • Loading branch information
talldan authored Jul 2, 2021
1 parent 2121e47 commit 829f88e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export function useInBetweenInserter() {
isBlockInsertionPointVisible,
isMultiSelecting,
getSelectedBlockClientIds,
getTemplateLock,
} = useSelect( blockEditorStore );
const { showInsertionPoint, hideInsertionPoint } = useDispatch(
blockEditorStore
Expand Down Expand Up @@ -68,6 +69,11 @@ export function useInBetweenInserter() {
rootClientId = blockElement.getAttribute( 'data-block' );
}

// Don't set the insertion point if the template is locked.
if ( getTemplateLock( rootClientId ) ) {
return;
}

const orientation =
getBlockListSettings( rootClientId )?.orientation ||
'vertical';
Expand Down
12 changes: 1 addition & 11 deletions packages/block-editor/src/store/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -1215,17 +1215,7 @@ export function getBlockInsertionPoint( state ) {
* @return {?boolean} Whether the insertion point is visible or not.
*/
export function isBlockInsertionPointVisible( state ) {
const insertionPoint = state.insertionPoint;

if ( ! state.insertionPoint ) {
return false;
}

if ( getTemplateLock( state, insertionPoint.rootClientId ) ) {
return false;
}

return true;
return state.insertionPoint !== null;
}

/**
Expand Down
31 changes: 0 additions & 31 deletions packages/block-editor/src/store/test/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -2255,43 +2255,12 @@ describe( 'selectors', () => {
expect( isBlockInsertionPointVisible( state ) ).toBe( false );
} );

it( 'should return false if the rootClientId has a truthy template lock', () => {
const state = {
insertionPoint: {
rootClientId: 'testClientId',
index: 5,
},
blockListSettings: {
testClientId: {
templateLock: 'all',
},
},
};

expect( isBlockInsertionPointVisible( state ) ).toBe( false );
} );

it( 'should return false if the rootClientId is undefined, and the settings has a template lock', () => {
const state = {
insertionPoint: {
rootClientId: undefined,
index: 5,
},
settings: {
templateLock: 'all',
},
};

expect( isBlockInsertionPointVisible( state ) ).toBe( false );
} );

it( 'should return true if assigned insertion point', () => {
const state = {
insertionPoint: {
rootClientId: undefined,
index: 5,
},
settings: {},
};

expect( isBlockInsertionPointVisible( state ) ).toBe( true );
Expand Down

0 comments on commit 829f88e

Please sign in to comment.