Skip to content

Commit

Permalink
call isMultiSelecting and is NavigationMode selectors where needed
Browse files Browse the repository at this point in the history
  • Loading branch information
youknowriad committed May 6, 2020
1 parent b73bb6d commit 7bb5a6f
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 42 deletions.
26 changes: 15 additions & 11 deletions packages/block-editor/src/components/block-list/block-wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ const BlockComponent = forwardRef(
isSelected,
isFirstMultiSelected,
isLastMultiSelected,
isMultiSelecting,
isNavigationMode,
isPartOfMultiSelection,
enableAnimation,
index,
Expand All @@ -51,16 +49,22 @@ const BlockComponent = forwardRef(
blockTitle,
wrapperProps,
} = useContext( BlockListBlockContext );
const { initialPosition } = useSelect(
const { initialPosition, shouldFocusFirstElement } = useSelect(
( select ) => {
if ( ! isSelected ) {
return {};
}
const {
getSelectedBlocksInitialCaretPosition,
isMultiSelecting: _isMultiSelecting,
isNavigationMode: _isNavigationMode,
} = select( 'core/block-editor' );

return {
initialPosition: select(
'core/block-editor'
).getSelectedBlocksInitialCaretPosition(),
shouldFocusFirstElement:
isSelected &&
! _isMultiSelecting() &&
! _isNavigationMode(),
initialPosition: isSelected
? getSelectedBlocksInitialCaretPosition()
: undefined,
};
},
[ isSelected ]
Expand Down Expand Up @@ -130,10 +134,10 @@ const BlockComponent = forwardRef(
};

useEffect( () => {
if ( ! isMultiSelecting && ! isNavigationMode && isSelected ) {
if ( shouldFocusFirstElement ) {
focusTabbable();
}
}, [ isSelected, isMultiSelecting, isNavigationMode ] );
}, [ shouldFocusFirstElement ] );

// Block Reordering animation
const animationStyle = useMovingAnimation(
Expand Down
6 changes: 0 additions & 6 deletions packages/block-editor/src/components/block-list/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ function BlockListBlock( {
toggleSelection,
index,
enableAnimation,
isNavigationMode,
isMultiSelecting,
} ) {
// In addition to withSelect, we should favor using useSelect in this
// component going forward to avoid leaking new props to the public API
Expand Down Expand Up @@ -152,8 +150,6 @@ function BlockListBlock( {
isSelected,
isFirstMultiSelected,
isLastMultiSelected,
isMultiSelecting,
isNavigationMode,
isPartOfMultiSelection,
enableAnimation,
index,
Expand Down Expand Up @@ -218,7 +214,6 @@ const applyWithSelect = withSelect(
hasSelectedInnerBlock,
getTemplateLock,
__unstableGetBlockWithoutInnerBlocks,
isNavigationMode,
isBlockHighlighted,
} = select( 'core/block-editor' );
const block = __unstableGetBlockWithoutInnerBlocks( clientId );
Expand Down Expand Up @@ -259,7 +254,6 @@ const applyWithSelect = withSelect(
isSelectionEnabled: isSelectionEnabled(),
isLocked: !! templateLock,
isFocusMode: focusMode && isLargeViewport,
isNavigationMode: isNavigationMode(),
isRTL,

// Users of the editor.BlockListBlock filter used to be able to
Expand Down
4 changes: 0 additions & 4 deletions packages/block-editor/src/components/block-list/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ function BlockList(
function selector( select ) {
const {
getBlockOrder,
isMultiSelecting,
getSelectedBlockClientId,
getMultiSelectedBlockClientIds,
hasMultiSelection,
Expand All @@ -48,7 +47,6 @@ function BlockList(

return {
blockClientIds: getBlockOrder( rootClientId ),
isMultiSelecting: isMultiSelecting(),
selectedBlockClientId: getSelectedBlockClientId(),
multiSelectedBlockClientIds: getMultiSelectedBlockClientIds(),
hasMultiSelection: hasMultiSelection(),
Expand All @@ -60,7 +58,6 @@ function BlockList(

const {
blockClientIds,
isMultiSelecting,
selectedBlockClientId,
multiSelectedBlockClientIds,
hasMultiSelection,
Expand Down Expand Up @@ -97,7 +94,6 @@ function BlockList(
rootClientId={ rootClientId }
clientId={ clientId }
isDraggable={ isDraggable }
isMultiSelecting={ isMultiSelecting }
// This prop is explicitely computed and passed down
// to avoid being impacted by the async mode
// otherwise there might be a small delay to trigger the animation.
Expand Down
22 changes: 13 additions & 9 deletions packages/block-editor/src/components/block-list/insertion-point.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ function Indicator( { clientId } ) {
}

export default function InsertionPoint( {
isMultiSelecting,
hasMultiSelection,
selectedBlockClientId,
children,
Expand All @@ -60,15 +59,20 @@ export default function InsertionPoint( {
const [ inserterElement, setInserterElement ] = useState( null );
const [ inserterClientId, setInserterClientId ] = useState( null );
const ref = useRef();
const { multiSelectedBlockClientIds } = useSelect( ( select ) => {
const { getMultiSelectedBlockClientIds } = select(
'core/block-editor'
);
const { multiSelectedBlockClientIds, isMultiSelecting } = useSelect(
( select ) => {
const {
getMultiSelectedBlockClientIds,
isMultiSelecting: _isMultiSelecting,
} = select( 'core/block-editor' );

return {
multiSelectedBlockClientIds: getMultiSelectedBlockClientIds(),
};
} );
return {
isMultiSelecting: _isMultiSelecting(),
multiSelectedBlockClientIds: getMultiSelectedBlockClientIds(),
};
},
[]
);

function onMouseMove( event ) {
if (
Expand Down
19 changes: 7 additions & 12 deletions packages/block-editor/src/components/block-list/root-container.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,13 @@ export const Context = createContext();
export const BlockNodes = createContext();

function selector( select ) {
const {
getSelectedBlockClientId,
hasMultiSelection,
isMultiSelecting,
} = select( 'core/block-editor' );
const { getSelectedBlockClientId, hasMultiSelection } = select(
'core/block-editor'
);

return {
selectedBlockClientId: getSelectedBlockClientId(),
hasMultiSelection: hasMultiSelection(),
isMultiSelecting: isMultiSelecting(),
};
}

Expand All @@ -52,11 +49,10 @@ function onDragStart( event ) {
}

function RootContainer( { children, className }, ref ) {
const {
selectedBlockClientId,
hasMultiSelection,
isMultiSelecting,
} = useSelect( selector, [] );
const { selectedBlockClientId, hasMultiSelection } = useSelect(
selector,
[]
);
const { selectBlock } = useDispatch( 'core/block-editor' );
const onSelectionStart = useMultiSelection( ref );

Expand All @@ -81,7 +77,6 @@ function RootContainer( { children, className }, ref ) {

return (
<InsertionPoint
isMultiSelecting={ isMultiSelecting }
hasMultiSelection={ hasMultiSelection }
selectedBlockClientId={ selectedBlockClientId }
containerRef={ ref }
Expand Down

0 comments on commit 7bb5a6f

Please sign in to comment.