Skip to content

fix: CRLF line endings no longer add width to a line - #2085

Merged
lavrton merged 1 commit into
konvajs:masterfrom
b84330808:fix-text-crlf-lines
Nov 9, 2026
Merged

lavrton merged 1 commit into
konvajs:masterfrom
b84330808:fix-text-crlf-lines

Conversation

@b84330808

Copy link
Copy Markdown
Contributor

split('\n') leaves the \r on every line, and canvas measures and draws it as a space. So text with CRLF line endings, for example from a file or an API, comes out one space wider than the same text with LF. In Chromium with fontSize: 20:

  • width() of 'hello world\r\nfoo' is 101.16 instead of 95.6
  • right-aligned lines sit 6px to the left
  • center-aligned lines and underlines use the same width
  • a line that just fits wraps at its last word, so height() goes from 40 to 60

The fix splits on /\r?\n/. text() still returns the original string.

split('\n') left the \r on every line, and canvas draws and measures it as a
space. Text with CRLF line endings came out one space wider: right and center
aligned lines sat off by that space, the underline ran past the text, and a
line that just fit wrapped at its last word.
@lavrton
lavrton merged commit aa06d25 into konvajs:master Nov 9, 2026
@lavrton

lavrton commented Nov 9, 2026

Copy link
Copy Markdown
Member

Thanks

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

Successfully merging this pull request may close these issues.

2 participants