Closed fonsp closed 6 months ago
I noticed that when changing paper sizes (A4 to A5), the window resize
event is not fired. But on Chrome, the window.matchMedia("print").addEventListener
event is fired whenever the page size changes. (On Firefox I can't find an event that matches a paper size change.)
I added this to the MWE to make cm aware of the matchMedia
event:
window.matchMedia("print").addEventListener("change", (x) => {
window.dispatchEvent(new CustomEvent("beforeprint"))
})
and it fixes the issue! (on Chrome) So maybe we could bind the onPrint
handler to matchMedia("print")
?
Attached patch uses media queries in a way that should help with this.
Describe the issue
When line wrapping is enabled, line numbers are sized to match line heights, and this is updated when the container resizes:
When printing, these recalculations don't happen. For example, printing this reproduction example with A5:
The long line went from wrapping 2 lines to 3 lines, but the line number element is still sized to 2 lines.
If you print on a page size that roughly matches the screen size, you don't see this issue.
Browser and platform
Chrome 122 and Firefox 123
Reproduction link
https://codemirror.net/try/?c=aW1wb3J0IHtiYXNpY1NldHVwLCBFZGl0b3JWaWV3fSBmcm9tICJjb2RlbWlycm9yIgppbXBvcnQge2phdmFzY3JpcHR9IGZyb20gIkBjb2RlbWlycm9yL2xhbmctamF2YXNjcmlwdCIKCmNvbnN0IGRvYyA9IGAKaGVsbG8Kc29tZSB0ZXh0CnRoaXMgaXMgYSBwcmV0dHkgbG9uZyBsaW5lLi4uLi4uLi4uLi4uLgpidXQKdGhlIG5leHQgb25lCmlzIHN1cGVyIGR1cGVyIGxvbmcgYW5kIHdpbGwgYWx3YXlzIHdyYXAgc2xrZGZqIGFsc2RrZmogYWxza2RmaiBhbHNrZGpmIGxha3NqZGYgbGthanMgZGZsa2phIHNkZmxraiBhbHNkamZrIGFzZGYKbGluZSA4CgoKCmxpbmUgMTIKYAoKbmV3IEVkaXRvclZpZXcoewogIGRvYywKICBleHRlbnNpb25zOiBbYmFzaWNTZXR1cCwgamF2YXNjcmlwdCgpLCBFZGl0b3JWaWV3LmxpbmVXcmFwcGluZ10sCiAgcGFyZW50OiBkb2N1bWVudC5ib2R5Cn0pCg==