From 080ace7b2c9125f12eaa5d90444475b600e01cc5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ella=20van=C2=A0Durpe?= Date: Tue, 2 Aug 2022 10:42:06 +0200 Subject: [PATCH 1/2] Writing flow: fix Shift+Arrow partial selection for nested blocks --- .../components/writing-flow/use-arrow-nav.js | 44 +------------------ 1 file changed, 1 insertion(+), 43 deletions(-) diff --git a/packages/block-editor/src/components/writing-flow/use-arrow-nav.js b/packages/block-editor/src/components/writing-flow/use-arrow-nav.js index 33755073af888..16a9564819918 100644 --- a/packages/block-editor/src/components/writing-flow/use-arrow-nav.js +++ b/packages/block-editor/src/components/writing-flow/use-arrow-nav.js @@ -17,7 +17,6 @@ import { useRefEffect } from '@wordpress/compose'; /** * Internal dependencies */ -import { isInSameBlock } from '../../utils/dom'; import { store as blockEditorStore } from '../../store'; /** @@ -130,11 +129,8 @@ export function getClosestTabbable( export default function useArrowNav() { const { - getSelectedBlockClientId, getMultiSelectedBlocksStartClientId, getMultiSelectedBlocksEndClientId, - getPreviousBlockClientId, - getNextBlockClientId, getSettings, hasMultiSelection, __unstableIsFullySelected, @@ -150,28 +146,6 @@ export default function useArrowNav() { verticalRect = null; } - /** - * Returns true if the given target field is the last in its block which - * can be considered for tab transition. For example, in a block with - * two text fields, this would return true when reversing from the first - * of the two fields, but false when reversing from the second. - * - * @param {Element} target Currently focused text field. - * @param {boolean} isReverse True if considering as the first field. - * - * @return {boolean} Whether field is at edge for tab transition. - */ - function isTabbableEdge( target, isReverse ) { - const closestTabbable = getClosestTabbable( - target, - isReverse, - node - ); - return ( - ! closestTabbable || ! isInSameBlock( target, closestTabbable ) - ); - } - function onKeyDown( event ) { const { keyCode, target } = event; const isUp = keyCode === UP; @@ -254,25 +228,9 @@ export default function useArrowNav() { // next, which is the exact reverse of LTR. const isReverseDir = isRTL( target ) ? ! isReverse : isReverse; const { keepCaretInsideBlock } = getSettings(); - const selectedBlockClientId = getSelectedBlockClientId(); if ( isShift ) { - const selectionEndClientId = - getMultiSelectedBlocksEndClientId(); - const selectionBeforeEndClientId = getPreviousBlockClientId( - selectionEndClientId || selectedBlockClientId - ); - const selectionAfterEndClientId = getNextBlockClientId( - selectionEndClientId || selectedBlockClientId - ); - - if ( - // Ensure that there is a target block. - ( ( isReverse && selectionBeforeEndClientId ) || - ( ! isReverse && selectionAfterEndClientId ) ) && - isTabbableEdge( target, isReverse ) && - isNavEdge( target, isReverse ) - ) { + if ( isNavEdge( target, isReverse ) ) { node.contentEditable = true; // Firefox doesn't automatically move focus. node.focus(); From 983a02a4286fec40f543d334443f47b776730371 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ella=20van=C2=A0Durpe?= Date: Thu, 4 Aug 2022 11:57:49 +0200 Subject: [PATCH 2/2] Fix content edges --- .../src/components/writing-flow/use-arrow-nav.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/packages/block-editor/src/components/writing-flow/use-arrow-nav.js b/packages/block-editor/src/components/writing-flow/use-arrow-nav.js index 16a9564819918..ea3e1888ce310 100644 --- a/packages/block-editor/src/components/writing-flow/use-arrow-nav.js +++ b/packages/block-editor/src/components/writing-flow/use-arrow-nav.js @@ -17,6 +17,7 @@ import { useRefEffect } from '@wordpress/compose'; /** * Internal dependencies */ +import { getBlockClientId } from '../../utils/dom'; import { store as blockEditorStore } from '../../store'; /** @@ -146,6 +147,15 @@ export default function useArrowNav() { verticalRect = null; } + function isClosestTabbableABlock( target, isReverse ) { + const closestTabbable = getClosestTabbable( + target, + isReverse, + node + ); + return closestTabbable && getBlockClientId( closestTabbable ); + } + function onKeyDown( event ) { const { keyCode, target } = event; const isUp = keyCode === UP; @@ -230,7 +240,10 @@ export default function useArrowNav() { const { keepCaretInsideBlock } = getSettings(); if ( isShift ) { - if ( isNavEdge( target, isReverse ) ) { + if ( + isClosestTabbableABlock( target, isReverse ) && + isNavEdge( target, isReverse ) + ) { node.contentEditable = true; // Firefox doesn't automatically move focus. node.focus();