Skip to content

Commit

Permalink
AI Proofread: Fix highlight on formatted texts (#38540)
Browse files Browse the repository at this point in the history
* AI Proofread: Get closest highlight element

* changelog
  • Loading branch information
renatoagds authored Jul 25, 2024
1 parent 2fbdedb commit 8566bd5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: other

Fix highlight not working on formatted texts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -45,7 +57,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';
Expand Down Expand Up @@ -74,7 +86,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 );
Expand Down

0 comments on commit 8566bd5

Please sign in to comment.