From bc710c909315d505420944925c7bdf7908b34899 Mon Sep 17 00:00:00 2001 From: Tetsuaki Hamano Date: Fri, 22 Sep 2023 22:26:53 +0900 Subject: [PATCH] Format Library: Try to fix highlight popover jumping --- packages/format-library/src/text-color/inline.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/packages/format-library/src/text-color/inline.js b/packages/format-library/src/text-color/inline.js index 7a2c2f92ea462..f71c776622258 100644 --- a/packages/format-library/src/text-color/inline.js +++ b/packages/format-library/src/text-color/inline.js @@ -137,6 +137,11 @@ export default function InlineColorUI( { onClose, contentRef, } ) { + const popoverAnchor = useAnchor( { + editableContentElement: contentRef.current, + settings, + } ); + /* As you change the text color by typing a HEX value into a field, the return value of document.getSelection jumps to the field you're editing, @@ -144,12 +149,8 @@ export default function InlineColorUI( { it will return null, since it can't find the element within the HEX input. This caches the last truthy value of the selection anchor reference. */ - const popoverAnchor = useCachedTruthy( - useAnchor( { - editableContentElement: contentRef.current, - settings, - } ) - ); + const cachedRect = useCachedTruthy( popoverAnchor.getBoundingClientRect() ); + popoverAnchor.getBoundingClientRect = () => cachedRect; return (