Skip to content

Commit d8d98cc

Browse files
ellatrixMamaduka
andauthored
Writing flow: fix Cmd+A from empty RichText (WordPress#75175)
Co-authored-by: ellatrix <ellatrix@git.wordpress.org> Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>
1 parent f11a7c0 commit d8d98cc

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

packages/dom/src/dom/is-entirely-selected.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44
import { assertIsDefined } from '../utils/assert-is-defined';
55
import isInputOrTextArea from './is-input-or-text-area';
66

7+
/**
8+
* Zero width non-breaking space, used as padding in the editable DOM tree when
9+
* it is empty otherwise.
10+
*/
11+
const ZWNBSP = '\ufeff';
12+
713
/**
814
* Check whether the contents of the element have been entirely selected.
915
* Returns true if there is no possibility of selection.
@@ -24,6 +30,14 @@ export default function isEntirelySelected( element ) {
2430
return true;
2531
}
2632

33+
// If the element is effectively empty (contains only the ZWNBSP
34+
// placeholder or nothing), consider it entirely selected since there's
35+
// nothing meaningful to select.
36+
const text = element.textContent || '';
37+
if ( text === '' || text === ZWNBSP ) {
38+
return true;
39+
}
40+
2741
const { ownerDocument } = element;
2842
const { defaultView } = ownerDocument;
2943
assertIsDefined( defaultView, 'defaultView' );

test/e2e/specs/editor/blocks/list.spec.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1655,4 +1655,40 @@ test.describe( 'List (@firefox)', () => {
16551655
},
16561656
] );
16571657
} );
1658+
1659+
test( 'should select the list wrapper with select all in empty list item', async ( {
1660+
editor,
1661+
page,
1662+
pageUtils,
1663+
} ) => {
1664+
await editor.insertBlock( { name: 'core/list' } );
1665+
1666+
// Verify the list item is selected after insertion.
1667+
await expect
1668+
.poll( () =>
1669+
page.evaluate(
1670+
() =>
1671+
window.wp.data
1672+
.select( 'core/block-editor' )
1673+
.getSelectedBlock()?.name
1674+
)
1675+
)
1676+
.toBe( 'core/list-item' );
1677+
1678+
// The list item is empty. Press cmd+a to select all, then again to select the list block.
1679+
await pageUtils.pressKeys( 'primary+a' );
1680+
await pageUtils.pressKeys( 'primary+a' );
1681+
1682+
// Verify the list block is selected using the block-editor store.
1683+
await expect
1684+
.poll( () =>
1685+
page.evaluate(
1686+
() =>
1687+
window.wp.data
1688+
.select( 'core/block-editor' )
1689+
.getSelectedBlock()?.name
1690+
)
1691+
)
1692+
.toBe( 'core/list' );
1693+
} );
16581694
} );

0 commit comments

Comments
 (0)