Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Line wrapping + line numbers not resizing to print media #1354

Closed
fonsp opened this issue Mar 13, 2024 · 3 comments
Closed

Line wrapping + line numbers not resizing to print media #1354

fonsp opened this issue Mar 13, 2024 · 3 comments

Comments

@fonsp
Copy link

fonsp commented Mar 13, 2024

Describe the issue

When line wrapping is enabled, line numbers are sized to match line heights, and this is updated when the container resizes:

Scherm­afbeelding 2024-03-13 om 11 40 11

When printing, these recalculations don't happen. For example, printing this reproduction example with A5:

Scherm­afbeelding 2024-03-13 om 11 40 02

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==

@fonsp
Copy link
Author

fonsp commented Mar 13, 2024

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.)

@fonsp
Copy link
Author

fonsp commented Mar 13, 2024

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")?

@marijnh
Copy link
Member

marijnh commented Mar 14, 2024

Attached patch uses media queries in a way that should help with this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants