diff --git a/packages/block-editor/src/components/block-list/insertion-point.js b/packages/block-editor/src/components/block-list/insertion-point.js index c7eb0e8d6ee80..275421ccbdc8e 100644 --- a/packages/block-editor/src/components/block-list/insertion-point.js +++ b/packages/block-editor/src/components/block-list/insertion-point.js @@ -98,36 +98,58 @@ function InsertionPointPopover( { isInserterForced, setIsInserterForced, containerRef, - showInsertionPoint, } ) { const element = getBlockDOMNode( clientId ); return ( - -
+ - { showInsertionPoint && ( +
- ) } - { ( isInserterShown || isInserterForced ) && ( - - ) } -
- + { ( isInserterShown || isInserterForced ) && ( + + ) } +
+
+ +
+
+ { ( isInserterShown || isInserterForced ) && ( + + ) } +
+ + ); } @@ -135,7 +157,7 @@ export default function InsertionPoint( { children, containerRef } ) { const [ isInserterShown, setIsInserterShown ] = useState( false ); const [ isInserterForced, setIsInserterForced ] = useState( false ); const [ inserterClientId, setInserterClientId ] = useState( null ); - const { isMultiSelecting, isInserterVisible, selectedClientId } = useSelect( + const { isMultiSelecting, isInserterVisible, blockOrder } = useSelect( ( select ) => { const { isMultiSelecting: _isMultiSelecting, @@ -150,67 +172,32 @@ export default function InsertionPoint( { children, containerRef } ) { return { isMultiSelecting: _isMultiSelecting(), isInserterVisible: isBlockInsertionPointVisible(), - selectedClientId: order[ insertionPoint.index ], + blockOrder: order, }; }, [] ); function onMouseMove( event ) { - if ( - ! event.target.classList.contains( - 'block-editor-block-list__layout' - ) - ) { - if ( isInserterShown ) { - setIsInserterShown( false ); - } - return; - } - - const rect = event.target.getBoundingClientRect(); - const offset = event.clientY - rect.top; - const element = Array.from( event.target.children ).find( - ( blockEl ) => { - return blockEl.offsetTop > offset; - } - ); - - if ( ! element ) { - return; - } - - const clientId = element.id.slice( 'block-'.length ); - - if ( ! clientId ) { - return; - } - - const elementRect = element.getBoundingClientRect(); + const clientId = event.target.id.slice( 'block-'.length ); + const index = blockOrder.findIndex( ( id ) => id === clientId ); - if ( - event.clientX > elementRect.right || - event.clientX < elementRect.left - ) { - if ( isInserterShown ) { - setIsInserterShown( false ); - } + // when there is no match return + if ( index === -1 ) { + setIsInserterShown( false ); return; } setIsInserterShown( true ); setInserterClientId( clientId ); } - const isVisible = isInserterShown || isInserterForced || isInserterVisible; return ( <> { ! isMultiSelecting && isVisible && ( ) } -
+
{ children }
diff --git a/packages/block-editor/src/components/block-list/style.scss b/packages/block-editor/src/components/block-list/style.scss index 3a67a193ff303..264025528acf1 100644 --- a/packages/block-editor/src/components/block-list/style.scss +++ b/packages/block-editor/src/components/block-list/style.scss @@ -428,16 +428,22 @@ } } +//.block-editor-block-list__insertion-point-inserter, +//.block-editor-block-list__block-popover-inserter { +// .block-editor-inserter__toggle.components-button { +// // Fade it in after a delay. +// animation: block-editor-inserter__toggle__fade-in-animation-delayed 0.3s ease; +// animation-fill-mode: forwards; +// @include reduce-motion("animation"); +// } +//} +// +//.block-editor-block-list__insertion-point-indicator { +// animation: block-editor-inserter__toggle__fade-in-animation-delayed 0.3s ease; +// animation-fill-mode: forwards; +// @include reduce-motion("animation"); +//} -.block-editor-block-list__insertion-point-inserter, -.block-editor-block-list__block-popover-inserter { - .block-editor-inserter__toggle.components-button { - // Fade it in after a delay. - animation: block-editor-inserter__toggle__fade-in-animation-delayed 0.3s ease; - animation-fill-mode: forwards; - @include reduce-motion("animation"); - } -} @keyframes block-editor-inserter__toggle__fade-in-animation-delayed { 0% {