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

Fix: hasSelectedInnerBlock does not accounts for multi selected innerBlocks #9592

Merged
merged 2 commits into from
Sep 5, 2018
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 4 additions & 1 deletion packages/editor/src/components/block-list/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,7 @@ export class BlockListBlock extends Component {
isPreviousBlockADefaultEmptyBlock,
hasSelectedInnerBlock,
isParentOfSelectedBlock,
hasMultiSelection,
} = this.props;
const isHovered = this.state.isHovered && ! isMultiSelecting;
const { name: blockName, isValid } = block;
Expand All @@ -387,7 +388,7 @@ export class BlockListBlock extends Component {
const showEmptyBlockSideInserter = ( isSelected || isHovered ) && isEmptyDefaultBlock;
const showSideInserter = ( isSelected || isHovered ) && isEmptyDefaultBlock;
const shouldAppearSelected = ! isFocusMode && ! hasFixedToolbar && ! showSideInserter && isSelected && ! isTypingWithinBlock;
const shouldAppearSelectedParent = ! isFocusMode && ! hasFixedToolbar && ! showSideInserter && hasSelectedInnerBlock && ! isTypingWithinBlock;
const shouldAppearSelectedParent = ! isFocusMode && ! hasFixedToolbar && ! showSideInserter && hasSelectedInnerBlock && ! isTypingWithinBlock && ! hasMultiSelection;
const shouldAppearHovered = ! isFocusMode && ! hasFixedToolbar && isHovered && ! isEmptyDefaultBlock;
// We render block movers and block settings to keep them tabbale even if hidden
const shouldRenderMovers = ! isFocusMode && ( isSelected || hoverArea === 'left' ) && ! showEmptyBlockSideInserter && ! isMultiSelecting && ! isPartOfMultiSelection && ! isTypingWithinBlock;
Expand Down Expand Up @@ -607,6 +608,7 @@ const applyWithSelect = withSelect( ( select, { clientId, rootClientId, isLargeV
getEditorSettings,
hasSelectedInnerBlock,
getTemplateLock,
hasMultiSelection,
} = select( 'core/editor' );
const isSelected = isBlockSelected( clientId );
const { hasFixedToolbar, focusMode } = getEditorSettings();
Expand Down Expand Up @@ -640,6 +642,7 @@ const applyWithSelect = withSelect( ( select, { clientId, rootClientId, isLargeV
block,
isSelected,
isParentOfSelectedBlock,
hasMultiSelection: hasMultiSelection(),
};
} );

Expand Down
1 change: 1 addition & 0 deletions packages/editor/src/store/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -1112,6 +1112,7 @@ export function hasSelectedInnerBlock( state, clientId, deep = false ) {
getBlockOrder( state, clientId ),
( innerClientId ) => (
isBlockSelected( state, innerClientId ) ||
isBlockMultiSelected( state, innerClientId ) ||
( deep && hasSelectedInnerBlock( state, innerClientId, deep ) )
)
);
Expand Down
29 changes: 29 additions & 0 deletions packages/editor/src/store/test/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -2240,6 +2240,35 @@ describe( 'selectors', () => {

expect( hasSelectedInnerBlock( state, 4 ) ).toBe( true );
} );

it( 'should return true if a multi selection exists that contains children of the block with the given ClientId', () => {
const state = {
editor: {
present: {
blockOrder: {
6: [ 5, 4, 3, 2, 1 ],
},
},
},
blockSelection: { start: 2, end: 4 },
};
expect( hasSelectedInnerBlock( state, 6 ) ).toBe( true );
} );

it( 'should return false if a multi selection exists bot does not contains children of the block with the given ClientId', () => {
const state = {
editor: {
present: {
blockOrder: {
3: [ 2, 1 ],
6: [ 5, 4 ],
},
},
},
blockSelection: { start: 5, end: 4 },
};
expect( hasSelectedInnerBlock( state, 3 ) ).toBe( false );
} );
} );

describe( 'isBlockWithinSelection', () => {
Expand Down