Skip to content

Commit

Permalink
Safari: fix Shift+Click multi select (#53440)
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix authored Aug 10, 2023
1 parent 530deb6 commit 92b0e12
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/block-editor/src/components/copy-handler/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ export function useClipboardHandler() {
if ( shouldHandleWholeBlocks && ! expandSelectionIsNeeded ) {
removeBlocks( selectedBlockClientIds );
} else {
event.target.ownerDocument.activeElement.contentEditable = false;
__unstableDeleteSelection();
}
} else if ( event.type === 'paste' ) {
Expand Down
7 changes: 7 additions & 0 deletions packages/block-editor/src/components/rich-text/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,13 @@ function RichTextWrapper(
props.className,
'rich-text'
) }
// Setting tabIndex to 0 is unnecessary, the element is already
// focusable because it's contentEditable. This also fixes a
// Safari bug where it's not possible to Shift+Click multi
// select blocks when Shift Clicking into an element with
// tabIndex because Safari will focus the element. However,
// Safari will correctly ignore nested contentEditable elements.
tabIndex={ props.tabIndex === 0 ? null : props.tabIndex }
/>
</>
);
Expand Down
4 changes: 3 additions & 1 deletion test/e2e/specs/editor/various/multi-block-selection.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1179,7 +1179,7 @@ test.describe( 'Multi-block selection', () => {
] );
} );

test( 'should partially select with shift + click', async ( {
test( 'should partially select with shift + click (@webkit)', async ( {
page,
editor,
} ) => {
Expand Down Expand Up @@ -1213,6 +1213,8 @@ test.describe( 'Multi-block selection', () => {
// Ensure clicking on the right half of the element.
position: { x: strongBox.width, y: strongBox.height / 2 },
modifiers: [ 'Shift' ],
// "<p>" intercepts pointer events in WebKit.
force: true,
} );
await page.keyboard.press( 'Backspace' );

Expand Down

0 comments on commit 92b0e12

Please sign in to comment.