Skip to content

Commit

Permalink
Writing flow: restore click redirect between blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix committed Jul 15, 2022
1 parent 4063556 commit e395ead
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ function BlockPopoverInbetween( {
key={ nextClientId + '--' + rootClientId }
{ ...props }
className={ classnames(
'block-editor-block-popover',
'block-editor-block-popover block-editor-block-popover-in-between',
props.className
) }
__unstableForcePosition
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function InsertionPointPopover( {
__unstablePopoverSlot,
__unstableContentRef,
} ) {
const { selectBlock, hideInsertionPoint } = useDispatch( blockEditorStore );
const { hideInsertionPoint } = useDispatch( blockEditorStore );
const openRef = useContext( InsertionPointOpenRef );
const ref = useRef();
const {
Expand Down Expand Up @@ -74,12 +74,6 @@ function InsertionPointPopover( {

const disableMotion = useReducedMotion();

function onClick( event ) {
if ( event.target === ref.current && nextClientId ) {
selectBlock( nextClientId, -1 );
}
}

function onFocus( event ) {
// Only handle click on the wrapper specifically, and not an event
// bubbled from the inserter itself.
Expand Down Expand Up @@ -190,11 +184,8 @@ function InsertionPointPopover( {
exit="start"
ref={ ref }
tabIndex={ -1 }
onClick={ onClick }
onFocus={ onFocus }
className={ classnames( className, {
'is-with-inserter': isInserterShown,
} ) }
className={ className }
onHoverEnd={ maybeHideInserterPoint }
>
<motion.div
Expand All @@ -205,7 +196,10 @@ function InsertionPointPopover( {
<motion.div
variants={ inserterVariants }
className={ classnames(
'block-editor-block-list__insertion-point-inserter'
'block-editor-block-list__insertion-point-inserter',
{
'is-with-inserter': isInserterShown,
}
) }
>
<Inserter
Expand Down
6 changes: 6 additions & 0 deletions packages/block-editor/src/components/block-tools/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
* Insertion Point.
*/

.components-popover.block-editor-block-popover.block-editor-block-popover-in-between,
.components-popover.block-editor-block-popover.block-editor-block-popover-in-between .components-popover__content > * {
pointer-events: none;
}

.block-editor-block-list__insertion-point {
position: absolute;
top: 0;
Expand Down Expand Up @@ -29,6 +34,7 @@

// This is the clickable plus.
.block-editor-block-list__insertion-point-inserter {
pointer-events: all;
// Don't show on mobile.
display: none;
position: absolute;
Expand Down
2 changes: 2 additions & 0 deletions packages/block-editor/src/components/writing-flow/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import useSelectAll from './use-select-all';
import useDragSelection from './use-drag-selection';
import useSelectionObserver from './use-selection-observer';
import useClickSelection from './use-click-selection';
import useClickRedirect from './use-click-redirect';
import useInput from './use-input';
import { store as blockEditorStore } from '../../store';

Expand All @@ -39,6 +40,7 @@ export function useWritingFlow() {
useDragSelection(),
useSelectionObserver(),
useClickSelection(),
useClickRedirect(),
useMultiSelection(),
useSelectAll(),
useArrowNav(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* WordPress dependencies
*/
import { useRefEffect } from '@wordpress/compose';

export default function useClickSelection() {
return useRefEffect( ( node ) => {
function onMouseDown() {
node.contentEditable = true;
// Firefox doesn't automatically move focus.
node.focus();
// The selection observer will turn off contentEditable after a
// selection change.
}

node.addEventListener( 'mousedown', onMouseDown );

return () => {
node.removeEventListener( 'mousedown', onMouseDown );
};
}, [] );
}

0 comments on commit e395ead

Please sign in to comment.