From 3e6925e8f4108fbfafeef1f4877ff994b8f72c0d Mon Sep 17 00:00:00 2001 From: George Mamadashvili Date: Fri, 17 Jul 2026 11:14:41 +0400 Subject: [PATCH] Rich Text: Restore the selection when focus returns to the editable --- .../src/hook/event-listeners/input-and-selection.js | 4 +++- test/e2e/specs/editor/various/block-notes.spec.js | 10 ++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/packages/rich-text/src/hook/event-listeners/input-and-selection.js b/packages/rich-text/src/hook/event-listeners/input-and-selection.js index bcf3fc9c022691..74d485202ac9ab 100644 --- a/packages/rich-text/src/hook/event-listeners/input-and-selection.js +++ b/packages/rich-text/src/hook/event-listeners/input-and-selection.js @@ -305,7 +305,9 @@ export default ( props ) => ( element ) => { // snapshot must not skip synchronization. selectionSnapshot = undefined; } else { - applyRecord( record.current, { domOnly: true } ); + // The document's selection may have moved elsewhere while the + // element was blurred, so restore it from the record. + applyRecord( record.current ); } onSelectionChange( record.current.start, record.current.end ); diff --git a/test/e2e/specs/editor/various/block-notes.spec.js b/test/e2e/specs/editor/various/block-notes.spec.js index 479c394993f2af..0355efc69b6879 100644 --- a/test/e2e/specs/editor/various/block-notes.spec.js +++ b/test/e2e/specs/editor/various/block-notes.spec.js @@ -1723,13 +1723,19 @@ test.describe( 'Block Notes', () => { /* * Pressing Escape closes the link popover and leaves the note - * form intact — focus does not get yanked out of the editor. + * form intact; focus does not get yanked out of the editor, and + * the selection is restored rather than left collapsed. */ await page.keyboard.press( 'Escape' ); await expect( page.getByRole( 'combobox', { name: 'Search or type URL' } ) ).toBeHidden(); - await expect( textbox ).toBeVisible(); + await expect( textbox ).toBeFocused(); + await expect + .poll( () => + page.evaluate( () => window.getSelection().toString() ) + ) + .toBe( 'visit example' ); } ); test( 'Cmd+K opens an unclipped link popover in the reply form', async ( {