From 64a550806c135aecd3f97bfd4cad984c32b8bfa1 Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Thu, 25 Jan 2024 21:02:49 +0000 Subject: [PATCH] Try a fix --- packages/format-library/src/link/inline.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/packages/format-library/src/link/inline.js b/packages/format-library/src/link/inline.js index 2d5f52406b678..c12ccc0b08f7f 100644 --- a/packages/format-library/src/link/inline.js +++ b/packages/format-library/src/link/inline.js @@ -212,7 +212,17 @@ function InlineLinkUI( { // This caches the last truthy value of the selection anchor reference. // This ensures the Popover is positioned correctly on initial submission of the link. const cachedRect = useCachedTruthy( popoverAnchor.getBoundingClientRect() ); - popoverAnchor.getBoundingClientRect = () => cachedRect; + + // If the link is not active (i.e. it is a new link) then we need to + // override the getBoundingClientRect method on the anchor element + // to return the cached value of the selection represented by the text + // that the user selected to be linked. + // If the link is active (i.e. it is an existing link) then we allow + // the default behaviour of the popover anchor to be used. This will get + // the anchor based on the `` element in the rich text. + if ( ! isActive ) { + popoverAnchor.getBoundingClientRect = () => cachedRect; + } async function handleCreate( pageTitle ) { const page = await createPageEntity( {