fix: Links with strikethrough do not have hover preview (#4841)

* fix: Links with strikethrough do not have hover preview

* refactor
This commit is contained in:
Tom Moor
2023-02-07 22:36:15 -05:00
committed by GitHub
parent bb1fe1a25f
commit 81f655f402
4 changed files with 39 additions and 43 deletions

View File

@@ -65,19 +65,18 @@ function Editor(props: Props, ref: React.RefObject<SharedEditor> | null) {
const localRef = React.useRef<SharedEditor>();
const preferences = auth.user?.preferences;
const previousHeadings = React.useRef<Heading[] | null>(null);
const [
activeLinkEvent,
setActiveLinkEvent,
] = React.useState<MouseEvent | null>(null);
activeLinkElement,
setActiveLink,
] = React.useState<HTMLAnchorElement | null>(null);
const handleLinkActive = React.useCallback((event: MouseEvent) => {
setActiveLinkEvent(event);
const handleLinkActive = React.useCallback((element: HTMLAnchorElement) => {
setActiveLink(element);
return false;
}, []);
const handleLinkInactive = React.useCallback(() => {
setActiveLinkEvent(null);
setActiveLink(null);
}, []);
const handleSearchLink = React.useCallback(
@@ -309,10 +308,9 @@ function Editor(props: Props, ref: React.RefObject<SharedEditor> | null) {
minHeight={props.bottomPadding}
/>
)}
{activeLinkEvent && !shareId && (
{activeLinkElement && !shareId && (
<HoverPreview
node={activeLinkEvent.target as HTMLAnchorElement}
event={activeLinkEvent}
element={activeLinkElement}
onClose={handleLinkInactive}
/>
)}