From ddcf77c4df77e9f7f164892afda064ecf96a326b Mon Sep 17 00:00:00 2001 From: Sainath Poojary Date: Thu, 27 Aug 2026 14:12:42 +0530 Subject: [PATCH 1/7] fix: batch selection change and block replacement in input rule --- .../components/rich-text/event-listeners/input-rules.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/block-editor/src/components/rich-text/event-listeners/input-rules.js b/packages/block-editor/src/components/rich-text/event-listeners/input-rules.js index ea576d7684a3eb..4ac56a28e0dd60 100644 --- a/packages/block-editor/src/components/rich-text/event-listeners/input-rules.js +++ b/packages/block-editor/src/components/rich-text/event-listeners/input-rules.js @@ -84,8 +84,11 @@ export default ( props ) => ( element ) => { } ); const block = transformation.transform( content ); - selectionChange( ...findSelection( [ block ] ) ); - onReplace( [ block ] ); + registry.batch( () => { + selectionChange( ...findSelection( [ block ] ) ); + onReplace( [ block ] ); + } ); + registry.dispatch( blockEditorStore ).__unstableMarkAutomaticChange(); return true; From 6a5e87f710dce5d97fdd89e1c140b67027fe7ad1 Mon Sep 17 00:00:00 2001 From: Sainath Poojary Date: Thu, 27 Aug 2026 14:19:23 +0530 Subject: [PATCH 2/7] test: add focus retention after backspace undo of heading prefix transforms --- .../specs/editor/various/rich-text.spec.js | 73 +++++++++++++++++++ 1 file changed, 73 insertions(+) diff --git a/test/e2e/specs/editor/various/rich-text.spec.js b/test/e2e/specs/editor/various/rich-text.spec.js index 8a0052ec03b440..6a6a8707900adc 100644 --- a/test/e2e/specs/editor/various/rich-text.spec.js +++ b/test/e2e/specs/editor/various/rich-text.spec.js @@ -187,6 +187,79 @@ 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 page.evaluate( () => new Promise( window.requestIdleCallback ) ); + + 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 retain focus after backspace-undo of a nested prefix transform', async ( { + editor, + page, + } ) => { + await editor.insertBlock( { + name: 'core/group', + innerBlocks: [ { name: 'core/paragraph' } ], + } ); + await editor.canvas.locator( '[data-type="core/paragraph"]' ).click(); + await page.keyboard.type( '## ' ); + await page.evaluate( () => new Promise( window.requestIdleCallback ) ); + + await expect.poll( editor.getBlocks ).toMatchObject( [ + { + name: 'core/group', + innerBlocks: [ { name: 'core/heading' } ], + }, + ] ); + + await page.keyboard.press( 'Backspace' ); + + await expect.poll( editor.getBlocks ).toMatchObject( [ + { + name: 'core/group', + innerBlocks: [ { name: 'core/paragraph' } ], + }, + ] ); + + await page.keyboard.type( 'hello' ); + + await expect.poll( editor.getBlocks ).toMatchObject( [ + { + name: 'core/group', + innerBlocks: [ + { + name: 'core/paragraph', + attributes: { content: '## hello' }, + }, + ], + }, + ] ); + } ); + test( 'should not undo backtick transform with backspace after typing', async ( { page, editor, From 0cdffc12fd790d335b9780b2c1a0b8c0efd16cfe Mon Sep 17 00:00:00 2001 From: Sainath Poojary Date: Thu, 27 Aug 2026 14:48:20 +0530 Subject: [PATCH 3/7] chore: update CHANGELOG --- packages/block-editor/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/block-editor/CHANGELOG.md b/packages/block-editor/CHANGELOG.md index a97050beaf0f55..d2af1122fff5b9 100644 --- a/packages/block-editor/CHANGELOG.md +++ b/packages/block-editor/CHANGELOG.md @@ -19,6 +19,7 @@ ### Bug Fixes +- Retain focus and caret position when undoing a prefix transform (e.g., ## , - , > ) with Backspace or Escape. - 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)). From 1afd90ffadbb98082d7419730a86419ee83218a3 Mon Sep 17 00:00:00 2001 From: Sainath Poojary Date: Thu, 27 Aug 2026 14:54:18 +0530 Subject: [PATCH 4/7] fix: update changelog to include PR reference --- packages/block-editor/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/block-editor/CHANGELOG.md b/packages/block-editor/CHANGELOG.md index d2af1122fff5b9..2c842247189967 100644 --- a/packages/block-editor/CHANGELOG.md +++ b/packages/block-editor/CHANGELOG.md @@ -19,7 +19,7 @@ ### Bug Fixes -- Retain focus and caret position when undoing a prefix transform (e.g., ## , - , > ) with Backspace or Escape. +- 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)). From 320dea0725cc1f5b01dcea3f264958f3029fda3c Mon Sep 17 00:00:00 2001 From: Sainath Poojary Date: Fri, 28 Aug 2026 17:33:15 +0530 Subject: [PATCH 5/7] fix: remove redundant idle callback and test for nested prefix transform --- .../specs/editor/various/rich-text.spec.js | 44 ------------------- 1 file changed, 44 deletions(-) diff --git a/test/e2e/specs/editor/various/rich-text.spec.js b/test/e2e/specs/editor/various/rich-text.spec.js index 6a6a8707900adc..22a833cae2b6fc 100644 --- a/test/e2e/specs/editor/various/rich-text.spec.js +++ b/test/e2e/specs/editor/various/rich-text.spec.js @@ -195,7 +195,6 @@ test.describe( 'RichText (@firefox, @webkit)', () => { .locator( 'role=document[name="Add default block"i]' ) .click(); await page.keyboard.type( '## ' ); - await page.evaluate( () => new Promise( window.requestIdleCallback ) ); await expect .poll( editor.getBlocks ) @@ -217,49 +216,6 @@ test.describe( 'RichText (@firefox, @webkit)', () => { ] ); } ); - test( 'should retain focus after backspace-undo of a nested prefix transform', async ( { - editor, - page, - } ) => { - await editor.insertBlock( { - name: 'core/group', - innerBlocks: [ { name: 'core/paragraph' } ], - } ); - await editor.canvas.locator( '[data-type="core/paragraph"]' ).click(); - await page.keyboard.type( '## ' ); - await page.evaluate( () => new Promise( window.requestIdleCallback ) ); - - await expect.poll( editor.getBlocks ).toMatchObject( [ - { - name: 'core/group', - innerBlocks: [ { name: 'core/heading' } ], - }, - ] ); - - await page.keyboard.press( 'Backspace' ); - - await expect.poll( editor.getBlocks ).toMatchObject( [ - { - name: 'core/group', - innerBlocks: [ { name: 'core/paragraph' } ], - }, - ] ); - - await page.keyboard.type( 'hello' ); - - await expect.poll( editor.getBlocks ).toMatchObject( [ - { - name: 'core/group', - innerBlocks: [ - { - name: 'core/paragraph', - attributes: { content: '## hello' }, - }, - ], - }, - ] ); - } ); - test( 'should not undo backtick transform with backspace after typing', async ( { page, editor, From a053e51753f2c2e96baef1dcc1c0c531ad5f5fea Mon Sep 17 00:00:00 2001 From: Sainath Poojary Date: Fri, 28 Aug 2026 17:36:13 +0530 Subject: [PATCH 6/7] fix: correct formatting --- packages/block-editor/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/block-editor/CHANGELOG.md b/packages/block-editor/CHANGELOG.md index 2c842247189967..af16a30c4b3211 100644 --- a/packages/block-editor/CHANGELOG.md +++ b/packages/block-editor/CHANGELOG.md @@ -19,7 +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)). +- 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)). From 347e50fa3ba5c91457cff0d42ecf9387e86cf521 Mon Sep 17 00:00:00 2001 From: Sainath Poojary Date: Fri, 28 Aug 2026 19:01:19 +0530 Subject: [PATCH 7/7] fix: add comments to clarify batch processing --- .../src/components/rich-text/event-listeners/input-rules.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/block-editor/src/components/rich-text/event-listeners/input-rules.js b/packages/block-editor/src/components/rich-text/event-listeners/input-rules.js index 4ac56a28e0dd60..8a7017ffc73966 100644 --- a/packages/block-editor/src/components/rich-text/event-listeners/input-rules.js +++ b/packages/block-editor/src/components/rich-text/event-listeners/input-rules.js @@ -84,6 +84,8 @@ export default ( props ) => ( element ) => { } ); const block = transformation.transform( content ); + // Batch so the undo history records the pre-transform selection, + // instead of the selection change here overwriting it first. registry.batch( () => { selectionChange( ...findSelection( [ block ] ) ); onReplace( [ block ] );