From fd2e2f8f531050f0f83e672d67dec5bc22f19aec Mon Sep 17 00:00:00 2001 From: Kjell Reigstad Date: Tue, 3 Sep 2019 12:15:50 -0400 Subject: [PATCH 1/2] Try showing move controls only for the selected block. --- packages/block-editor/src/components/block-list/block.js | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/packages/block-editor/src/components/block-list/block.js b/packages/block-editor/src/components/block-list/block.js index ef3df798c1a50a..076fe6d9bc9904 100644 --- a/packages/block-editor/src/components/block-list/block.js +++ b/packages/block-editor/src/components/block-list/block.js @@ -49,7 +49,6 @@ import BlockInsertionPoint from './insertion-point'; import IgnoreNestedEvents from '../ignore-nested-events'; import InserterWithShortcuts from '../inserter-with-shortcuts'; import Inserter from '../inserter'; -import useHoveredArea from './hover-area'; import { isInsideRootBlock } from '../../utils/dom'; import useMovingAnimation from './moving-animation'; @@ -81,7 +80,6 @@ function BlockListBlock( { isParentOfSelectedBlock, isDraggable, isSelectionEnabled, - isRTL, className, name, isValid, @@ -117,9 +115,6 @@ function BlockListBlock( { // Reference to the block edit node const blockNodeRef = useRef(); - // Hovered area of the block - const hoverArea = useHoveredArea( wrapper ); - const breadcrumb = useRef(); // Keep track of touchstart to disable hover on iOS @@ -404,7 +399,7 @@ function BlockListBlock( { // We render block movers and block settings to keep them tabbale even if hidden const shouldRenderMovers = ! isNavigationMode && - ( isSelected || hoverArea === ( isRTL ? 'right' : 'left' ) ) && + isSelected && ! showEmptyBlockSideInserter && ! isPartOfMultiSelection && ! isTypingWithinBlock; @@ -523,7 +518,7 @@ function BlockListBlock( { Date: Mon, 9 Sep 2019 08:03:12 -0400 Subject: [PATCH 2/2] Delete hover-area.js --- .../src/components/block-list/hover-area.js | 41 ------------------- 1 file changed, 41 deletions(-) delete mode 100644 packages/block-editor/src/components/block-list/hover-area.js diff --git a/packages/block-editor/src/components/block-list/hover-area.js b/packages/block-editor/src/components/block-list/hover-area.js deleted file mode 100644 index 36664e3c9d797c..00000000000000 --- a/packages/block-editor/src/components/block-list/hover-area.js +++ /dev/null @@ -1,41 +0,0 @@ -/** - * WordPress dependencies - */ -import { useState, useEffect } from '@wordpress/element'; - -const useHoveredArea = ( wrapper ) => { - const [ hoveredArea, setHoveredArea ] = useState( null ); - - useEffect( () => { - const onMouseLeave = () => { - if ( hoveredArea ) { - setHoveredArea( null ); - } - }; - - const onMouseMove = ( event ) => { - const { width, left, right } = wrapper.current.getBoundingClientRect(); - - let newHoveredArea = null; - if ( ( event.clientX - left ) < width / 3 ) { - newHoveredArea = 'left'; - } else if ( ( right - event.clientX ) < width / 3 ) { - newHoveredArea = 'right'; - } - - setHoveredArea( newHoveredArea ); - }; - - wrapper.current.addEventListener( 'mousemove', onMouseMove ); - wrapper.current.addEventListener( 'mouseleave', onMouseLeave ); - - return () => { - wrapper.current.removeEventListener( 'mousemove', onMouseMove ); - wrapper.current.removeEventListener( 'mouseleave', onMouseLeave ); - }; - }, [] ); - - return hoveredArea; -}; - -export default useHoveredArea;