From 9c923933d0381b819188452e5936508799d92bf9 Mon Sep 17 00:00:00 2001 From: Ella van Durpe Date: Sun, 5 Jul 2020 17:19:36 +0300 Subject: [PATCH] Inserter: fix line to show again --- .../components/block-list/insertion-point.js | 107 ++++++++++-------- 1 file changed, 62 insertions(+), 45 deletions(-) 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 1a64d9cf674596..942ff8950b992b 100644 --- a/packages/block-editor/src/components/block-list/insertion-point.js +++ b/packages/block-editor/src/components/block-list/insertion-point.js @@ -33,7 +33,7 @@ function Indicator( { clientId } ) { return ( isBlockInsertionPointVisible() && insertionPoint.index === blockIndex && - insertionPoint.rootClientId === rootClientId + ( insertionPoint.rootClientId || '' ) === rootClientId ); }, [ clientId ] @@ -59,20 +59,30 @@ export default function InsertionPoint( { const [ inserterElement, setInserterElement ] = useState( null ); const [ inserterClientId, setInserterClientId ] = useState( null ); const ref = useRef(); - const { multiSelectedBlockClientIds, isMultiSelecting } = useSelect( - ( select ) => { - const { - getMultiSelectedBlockClientIds, - isMultiSelecting: _isMultiSelecting, - } = select( 'core/block-editor' ); - - return { - isMultiSelecting: _isMultiSelecting(), - multiSelectedBlockClientIds: getMultiSelectedBlockClientIds(), - }; - }, - [] - ); + const { + multiSelectedBlockClientIds, + isMultiSelecting, + isInserterVisible, + selectedClientId, + } = useSelect( ( select ) => { + const { + getMultiSelectedBlockClientIds, + isMultiSelecting: _isMultiSelecting, + isBlockInsertionPointVisible, + getBlockInsertionPoint, + getBlockOrder, + } = select( 'core/block-editor' ); + + const insertionPoint = getBlockInsertionPoint(); + const order = getBlockOrder( insertionPoint.rootClientId ); + + return { + isMultiSelecting: _isMultiSelecting(), + multiSelectedBlockClientIds: getMultiSelectedBlockClientIds(), + isInserterVisible: isBlockInsertionPointVisible(), + selectedClientId: order[ insertionPoint.index ], + }; + }, [] ); function onMouseMove( event ) { if ( @@ -145,14 +155,17 @@ export default function InsertionPoint( { const isInserterHidden = hasMultiSelection ? multiSelectedBlockClientIds.includes( inserterClientId ) : inserterClientId === selectedBlockClientId; + const isVisible = isInserterShown || isInserterForced || isInserterVisible; + const selectedElement = + inserterElement || getBlockDOMNode( selectedClientId ); return ( <> - { ! isMultiSelecting && ( isInserterShown || isInserterForced ) && ( + { ! isMultiSelecting && isVisible && (
- - { /* eslint-disable-next-line jsx-a11y/no-static-element-interactions, jsx-a11y/click-events-have-key-events */ } -
setIsInserterForced( true ) } - onBlur={ () => setIsInserterForced( false ) } - onClick={ focusClosestTabbable } - // While ideally it would be enough to capture the - // bubbling focus event from the Inserter, due to the - // characteristics of click focusing of `button`s in - // Firefox and Safari, it is not reliable. - // - // See: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button#Clicking_and_focus - tabIndex={ -1 } - className={ classnames( - 'block-editor-block-list__insertion-point-inserter', - { - 'is-inserter-hidden': isInserterHidden, - } - ) } - > - -
+ + { ( isInserterShown || isInserterForced ) && ( + /* eslint-disable-next-line jsx-a11y/no-static-element-interactions, jsx-a11y/click-events-have-key-events */ +
setIsInserterForced( true ) } + onBlur={ () => setIsInserterForced( false ) } + onClick={ focusClosestTabbable } + // While ideally it would be enough to capture the + // bubbling focus event from the Inserter, due to the + // characteristics of click focusing of `button`s in + // Firefox and Safari, it is not reliable. + // + // See: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button#Clicking_and_focus + tabIndex={ -1 } + className={ classnames( + 'block-editor-block-list__insertion-point-inserter', + { + 'is-inserter-hidden': isInserterHidden, + } + ) } + > + +
+ ) }
) }