Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Safari: fix Shift+Click multi select #53440

Merged
merged 3 commits into from
Aug 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is actually a bug introduced in #40098. When using __unstableDeleteSelection, contenteditable needs to be turned off first (see other instances). Ideally we should move this logic to writing flow and build in clipboard handling there.

__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