diff --git a/frontend/common/useEventListener.js b/frontend/common/useEventListener.js index 94b8911846..86fe78156f 100644 --- a/frontend/common/useEventListener.js +++ b/frontend/common/useEventListener.js @@ -1,7 +1,7 @@ import { useCallback, useEffect } from "../imports/Preact.js" export const useEventListener = ( - /** @type {Document | HTMLElement | Window | null} */ element, + /** @type {Document | HTMLElement | Window | EventSource | MediaQueryList | null} */ element, /** @type {string} */ event_name, /** @type {EventListenerOrEventListenerObject} */ handler, /** @type {any[] | undefined} */ deps diff --git a/frontend/components/ExportBanner.js b/frontend/components/ExportBanner.js index a013995680..36e891c5df 100644 --- a/frontend/components/ExportBanner.js +++ b/frontend/components/ExportBanner.js @@ -64,10 +64,11 @@ export const ExportBanner = ({ notebook_id, print_title, open, onClose, notebook useEventListener( window, "beforeprint", - () => { - console.log("beforeprint") - print_old_title_ref.current = document.title - document.title = print_title.replace(/\.jl$/, "").replace(/\.plutojl$/, "") + (e) => { + if (!e.detail?.fake) { + print_old_title_ref.current = document.title + document.title = print_title.replace(/\.jl$/, "").replace(/\.plutojl$/, "") + } }, [print_title] ) @@ -79,6 +80,15 @@ export const ExportBanner = ({ notebook_id, print_title, open, onClose, notebook }, [print_title] ) + // https://github.com/codemirror/dev/issues/1354 + useEventListener( + window.matchMedia("print"), + "change", + () => { + // window.dispatchEvent(new CustomEvent("beforeprint", { detail: { fake: true } })) + }, + [] + ) const element_ref = useRef(/** @type {HTMLDialogElement?} */ (null))