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

List: use nested blocks #42711

Merged
merged 17 commits into from
Aug 24, 2022
Prev Previous commit
Next Next commit
Fix select all
  • Loading branch information
ellatrix authored and oandregal committed Aug 24, 2022
commit 89619effa5c46bf8a7487bb646269b7eded57a1c
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,12 @@ export function useFocusFirstElement( clientId ) {
const { ownerDocument } = ref.current;

// Do not focus the block if it already contains the active element.
if ( ref.current.contains( ownerDocument.activeElement ) ) {
if ( isInsideRootBlock( ref.current, ownerDocument.activeElement ) ) {
return;
}

ownerDocument.defaultView.getSelection().removeAllRanges();

// Find all tabbables within node.
const textInputs = focus.tabbable
.find( ref.current )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,34 +37,20 @@ export default function useSelectAll() {
return;
}

event.preventDefault();

const [ firstSelectedClientId ] = selectedClientIds;
const rootClientId = getBlockRootClientId( firstSelectedClientId );
let blockClientIds = getBlockOrder( rootClientId );
const blockClientIds = getBlockOrder( rootClientId );

// If we have selected all sibling nested blocks, try selecting up a
// level. See: https://github.com/WordPress/gutenberg/pull/31859/
if ( selectedClientIds.length === blockClientIds.length ) {
blockClientIds = getBlockOrder(
getBlockRootClientId( rootClientId )
);
}

const firstClientId = first( blockClientIds );
const lastClientId = last( blockClientIds );

event.preventDefault();

if ( firstClientId === lastClientId ) {
// If there's any selection remaining, the copy handler will
// only copy the native selection.
event.target.ownerDocument.defaultView
.getSelection()
.removeAllRanges();
selectBlock( firstClientId );
selectBlock( rootClientId );
return;
}

multiSelect( firstClientId, lastClientId );
multiSelect( first( blockClientIds ), last( blockClientIds ) );
}

node.addEventListener( 'keydown', onKeyDown );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,24 @@ exports[`RichText should only mutate text data on input 1`] = `

exports[`RichText should paste list contents into paragraph 1`] = `
"<!-- wp:list -->
<ul><li>1<ul><li>2</li></ul></li></ul>
<ul><!-- wp:list-item -->
<li>1<!-- wp:list -->
<ul><!-- wp:list-item -->
<li>2</li>
<!-- /wp:list-item --></ul>
<!-- /wp:list --></li>
<!-- /wp:list-item --></ul>
<!-- /wp:list -->

<!-- wp:paragraph -->
<p>1<br>2</p>
<!-- /wp:paragraph -->"
<!-- wp:list -->
<ul><!-- wp:list-item -->
<li>1<!-- wp:list -->
<ul><!-- wp:list-item -->
<li>2</li>
<!-- /wp:list-item --></ul>
<!-- /wp:list --></li>
<!-- /wp:list-item --></ul>
<!-- /wp:list -->"
`;

exports[`RichText should paste paragraph contents into list 1`] = `
Expand Down
5 changes: 3 additions & 2 deletions packages/e2e-tests/specs/editor/various/rich-text.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -479,12 +479,13 @@ describe( 'RichText', () => {
await pressKeyWithModifier( 'primary', 'a' );
// Select the parent list item.
await pressKeyWithModifier( 'primary', 'a' );
// Select all the parent list item text.
await pressKeyWithModifier( 'primary', 'a' );
// Select the entire list.
await pressKeyWithModifier( 'primary', 'a' );
await pressKeyWithModifier( 'primary', 'c' );

// Collapse the selection to the end.
await insertBlock( 'Paragraph' );
await page.keyboard.press( 'Enter' );

// Paste paragraph contents.
await pressKeyWithModifier( 'primary', 'v' );
Expand Down