From d8d8e73c993e545269b5e8fa9dfd55cf0366b0f0 Mon Sep 17 00:00:00 2001 From: Renato Augusto Gama dos Santos Date: Thu, 25 Jul 2024 10:10:12 -0300 Subject: [PATCH 1/2] AI Proofread: Get closest highlight element --- .../components/breve/features/events.ts | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/projects/plugins/jetpack/extensions/plugins/ai-assistant-plugin/components/breve/features/events.ts b/projects/plugins/jetpack/extensions/plugins/ai-assistant-plugin/components/breve/features/events.ts index eba52855ee3b6..82cd2462f031a 100644 --- a/projects/plugins/jetpack/extensions/plugins/ai-assistant-plugin/components/breve/features/events.ts +++ b/projects/plugins/jetpack/extensions/plugins/ai-assistant-plugin/components/breve/features/events.ts @@ -18,6 +18,18 @@ let anchorTimeout: number; let isFirstHover = ! localStorage.getItem( 'jetpack-ai-breve-first-hover' ); +function getHighlightEl( el: HTMLElement ) { + if ( el === document.body ) { + return null; + } + + if ( el.getAttribute( 'data-type' ) === null ) { + return getHighlightEl( el.parentElement ); + } + + return el; +} + async function handleMouseEnter( e: MouseEvent ) { if ( isFirstHover ) { await showAiAssistantSection(); @@ -38,7 +50,7 @@ async function handleMouseEnter( e: MouseEvent ) { return; } - const el = e.target as HTMLElement; + const el = getHighlightEl( e.target as HTMLElement ); let virtual = el; const shouldPointToCursor = el.getAttribute( 'data-type' ) === 'long-sentences'; @@ -67,7 +79,7 @@ async function handleMouseEnter( e: MouseEvent ) { ( dispatch( 'jetpack/ai-breve' ) as BreveDispatch ).setHighlightHover( true ); ( dispatch( 'jetpack/ai-breve' ) as BreveDispatch ).setPopoverAnchor( { - target: e.target as HTMLElement, + target: el, virtual: virtual, } as Anchor ); }, 100 ); From 6651189fda35c34848a808d591e68b2015f0f051 Mon Sep 17 00:00:00 2001 From: Renato Augusto Gama dos Santos Date: Thu, 25 Jul 2024 10:11:00 -0300 Subject: [PATCH 2/2] changelog --- .../plugins/jetpack/changelog/fix-ai-proofread-popover-hover | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 projects/plugins/jetpack/changelog/fix-ai-proofread-popover-hover diff --git a/projects/plugins/jetpack/changelog/fix-ai-proofread-popover-hover b/projects/plugins/jetpack/changelog/fix-ai-proofread-popover-hover new file mode 100644 index 0000000000000..1330c8c34acef --- /dev/null +++ b/projects/plugins/jetpack/changelog/fix-ai-proofread-popover-hover @@ -0,0 +1,4 @@ +Significance: minor +Type: other + +Fix highlight not working on formatted texts