Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AI Proofread: Fix highlight on formatted texts #38540

Merged
merged 2 commits into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 All @@ -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';
Expand Down Expand Up @@ -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 );
Expand Down
Loading