Offline, privacy-first grammar checker. Fast, open-source, Rust-powered
fix: added exception so popover doesn't close before click event
Elijah Potter5c29d58207dc
diff --git a/src/harper/Box.ts b/src/harper/Box.tsindex 6cd7dafa3..64c586fab 100644--- a/src/harper/Box.ts+++ b/src/harper/Box.ts@@ -15,3 +15,14 @@ export type LintBox = Box & {lint: Lint;applySuggestion: ( sug: Suggestion ) => void;};++export function isPointInBox( point: [ number, number ], box: Box ) {+ let [ x, y ] = point;++ return (+ x > box.x &&+ x < box.x + box.width &&+ y > box.y &&+ y < box.y + box.height+ );+}diff --git a/src/harper/SuggestionControl.tsx b/src/harper/SuggestionControl.tsxindex 58895b449..23ec56b0a 100644--- a/src/harper/SuggestionControl.tsx+++ b/src/harper/SuggestionControl.tsx@@ -5,7 +5,7 @@ import React, {useRef,useState,} from 'react';-import { LintBox } from './Box';+import { isPointInBox, LintBox } from './Box';import { SuggestionKind } from 'harper.js';function suggestionText(@@ -40,13 +40,13 @@ export default function SuggestionControl( { lintBox }: { lintBox: LintBox } ) {return;}- let rect = underlineRef.current.getBoundingClientRect();+ let underlineRect = underlineRef.current.getBoundingClientRect();+ let popoverRect = popoverRef.current?.getBoundingClientRect();if (- e.clientX > rect.x &&- e.clientX < rect.x + width &&- e.clientY > rect.y &&- e.clientY < rect.y + height+ isPointInBox( [ e.clientX, e.clientY ], underlineRect ) ||+ ( popoverRect &&+ isPointInBox( [ e.clientX, e.clientY ], popoverRect ) )) {setShowPopover( () => true );} else {@@ -65,7 +65,7 @@ export default function SuggestionControl( { lintBox }: { lintBox: LintBox } ) {mouseUp);};- }, [ underlineRef.current ] );+ }, [ underlineRef.current, popoverRef.current ] );return (<>