Skip to content

Commit

Permalink
Fix misaligned line numbers + line wrapping in PDF output (fonsp#2848)
Browse files Browse the repository at this point in the history
  • Loading branch information
fonsp authored Mar 13, 2024
1 parent 0a7c946 commit 1978e1b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
2 changes: 1 addition & 1 deletion frontend/common/useEventListener.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down
18 changes: 14 additions & 4 deletions frontend/components/ExportBanner.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]
)
Expand All @@ -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))

Expand Down

0 comments on commit 1978e1b

Please sign in to comment.