From 549dcf308e56410d8e36174449ae4867815b2d02 Mon Sep 17 00:00:00 2001 From: Curt Grimes Date: Wed, 22 Dec 2021 18:44:19 -0600 Subject: [PATCH] Allow metronome sound to continue to play from collapsed sidebar This makes it match the behavior of audio files playing from a collapsed sidebar. Closes #2. --- .../useParentMarkdownWrapperVisibilityWatcher.ts | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/hooks/useParentMarkdownWrapperVisibilityWatcher.ts b/src/hooks/useParentMarkdownWrapperVisibilityWatcher.ts index 71e0d6a..896d4fd 100644 --- a/src/hooks/useParentMarkdownWrapperVisibilityWatcher.ts +++ b/src/hooks/useParentMarkdownWrapperVisibilityWatcher.ts @@ -19,12 +19,19 @@ export function useParentMarkdownWrapperVisibilityWatcher( elementRef.value.closest(".markdown-reading-view") : null; + // We want to consider it still visible if it's + // in a sidebar to match the behavior of audio players. + const isInSidebar = () => + markdownWrapperParent.closest( + ".mod-left-split, .mod-right-split" + ) !== null; + const { stop } = useIntersectionObserver( markdownWrapperParent as MaybeElementRef, (entries) => - (isVisible.value = entries.some( - (entry) => entry.isIntersecting - )) + (isVisible.value = + entries.some((entry) => entry.isIntersecting) || + isInSidebar()) ); stopFunction.value = stop;