diff --git a/packages/rich-text/src/component/use-input-and-selection.js b/packages/rich-text/src/component/use-input-and-selection.js index ecfcc2151a989..1b0cd03829469 100644 --- a/packages/rich-text/src/component/use-input-and-selection.js +++ b/packages/rich-text/src/component/use-input-and-selection.js @@ -241,7 +241,7 @@ export function useInputAndSelection( props ) { activeFormats: EMPTY_ACTIVE_FORMATS, }; } else { - applyRecord( record.current ); + applyRecord( record.current, { domOnly: true } ); } onSelectionChange( record.current.start, record.current.end ); diff --git a/test/e2e/specs/editor/blocks/links.spec.js b/test/e2e/specs/editor/blocks/links.spec.js index 7ebdb33b10353..0a95064032f83 100644 --- a/test/e2e/specs/editor/blocks/links.spec.js +++ b/test/e2e/specs/editor/blocks/links.spec.js @@ -878,6 +878,48 @@ test.describe( 'Links', () => { ] ); } ); + // Fix for https://github.com/WordPress/gutenberg/issues/58322 + test( 'can click links within the same paragraph to open the correct link preview (@firefox)', async ( { + editor, + LinkUtils, + } ) => { + // Create a paragraph with two links + await editor.insertBlock( { + name: 'core/paragraph', + attributes: { + content: `Donate to the WordPress Foundation to support Gutenberg`, + }, + } ); + + // Click on "Gutenberg" link in the canvas + await editor.canvas + .getByRole( 'link', { + name: 'Gutenberg', + } ) + .click(); + + const linkPopover = LinkUtils.getLinkPopover(); + await expect( linkPopover ).toBeVisible(); + await expect( + linkPopover.getByText( 'wordpress.org/gutenberg' ) + ).toBeVisible(); + + // Click the other link in the same paragraph. We need a short delay between mousdown and mouseup to get the popover to show + await editor.canvas + .getByRole( 'link', { + name: 'WordPress', + } ) + .click( { delay: 100 } ); + + await expect( linkPopover ).toBeVisible(); + await expect( + linkPopover.getByText( 'wordpress.org/gutenberg' ) + ).toBeHidden(); + await expect( + linkPopover.getByText( 'wordpressfoundation.org/donate/' ) + ).toBeVisible(); + } ); + test.describe( 'Editing link text', () => { test( 'should allow for modification of link text via the Link UI', async ( { page,