Skip to content

Commit

Permalink
Only scroll page for multi-selectiions (#21460)
Browse files Browse the repository at this point in the history
  • Loading branch information
youknowriad authored and whyisjake committed Apr 22, 2020
1 parent 0fa11e0 commit 889ee28
Showing 1 changed file with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,25 @@ import { getBlockDOMNode } from '../../utils/dom';
*/
export default function MultiSelectScrollIntoView() {
const selector = ( select ) => {
const { getBlockSelectionEnd, isMultiSelecting } = select(
'core/block-editor'
);
const {
getBlockSelectionEnd,
hasMultiSelection,
isMultiSelecting,
} = select( 'core/block-editor' );

return {
selectionEnd: getBlockSelectionEnd(),
isMultiSelection: hasMultiSelection(),
isMultiSelecting: isMultiSelecting(),
};
};
const { selectionEnd, isMultiSelecting } = useSelect( selector, [] );
const { isMultiSelection, selectionEnd, isMultiSelecting } = useSelect(
selector,
[]
);

useEffect( () => {
if ( ! selectionEnd || isMultiSelecting ) {
if ( ! selectionEnd || isMultiSelecting || ! isMultiSelection ) {
return;
}

Expand All @@ -54,7 +60,7 @@ export default function MultiSelectScrollIntoView() {
scrollIntoView( extentNode, scrollContainer, {
onlyScrollIfNeeded: true,
} );
}, [ selectionEnd, isMultiSelecting ] );
}, [ isMultiSelection, selectionEnd, isMultiSelecting ] );

return null;
}

0 comments on commit 889ee28

Please sign in to comment.