Skip to content
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
1 change: 1 addition & 0 deletions packages/block-editor/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

### Bug Fixes

- Retain focus and caret position when undoing a prefix transform (e.g. `## `, `- `, `> `) with Backspace or Escape ([#82116](https://github.com/WordPress/gutenberg/pull/82116)).
- Hide the Layout panel when a block has layout editing enabled but all controls for its layout type are disabled ([#81968](https://github.com/WordPress/gutenberg/pull/81968)).
- `DuotoneControl`: Keep the picked preset's identity when applying a duotone to a block. Two presets can hold the same pair of colors, and the applied preset was resolved by matching colors, so the first of any duplicate pair was saved and both appeared selected ([#81605](https://github.com/WordPress/gutenberg/pull/81605)).
- `InnerBlocks`: Resolve the `default` of a block's `layout` support before providing it to inner blocks. A block that declared its layout only as a support default, such as the Gallery, previously handed its children the raw support config, which has no `type`, so the children resolved to the flow layout instead. As a result an Image nested in a Gallery offered left/center/right alignment, which the flex layout does not permit ([#81606](https://github.com/WordPress/gutenberg/pull/81606)).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,13 @@ export default ( props ) => ( element ) => {
} );
const block = transformation.transform( content );

selectionChange( ...findSelection( [ block ] ) );
onReplace( [ block ] );
// Batch so the undo history records the pre-transform selection,
// instead of the selection change here overwriting it first.
registry.batch( () => {
Comment thread
Mamaduka marked this conversation as resolved.
Resolved
selectionChange( ...findSelection( [ block ] ) );
onReplace( [ block ] );
} );

registry.dispatch( blockEditorStore ).__unstableMarkAutomaticChange();

return true;
Expand Down
29 changes: 29 additions & 0 deletions test/e2e/specs/editor/various/rich-text.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,35 @@ test.describe( 'RichText (@firefox, @webkit)', () => {
] );
} );

test( 'should retain focus after backspace-undo of heading prefix transform', async ( {
page,
editor,
} ) => {
await editor.canvas
.locator( 'role=document[name="Add default block"i]' )
.click();
await page.keyboard.type( '## ' );

await expect
.poll( editor.getBlocks )
.toMatchObject( [ { name: 'core/heading' } ] );

await page.keyboard.press( 'Backspace' );

await expect
.poll( editor.getBlocks )
.toMatchObject( [ { name: 'core/paragraph' } ] );

await page.keyboard.type( 'hello' );

await expect.poll( editor.getBlocks ).toMatchObject( [
{
name: 'core/paragraph',
attributes: { content: '## hello' },
},
] );
} );

test( 'should not undo backtick transform with backspace after typing', async ( {
page,
editor,
Expand Down
Loading