diff --git a/src/render/canvas/__tests__/textarea-layout.ts b/src/render/canvas/__tests__/textarea-layout.ts index 9ca3553..1005d7e 100644 --- a/src/render/canvas/__tests__/textarea-layout.ts +++ b/src/render/canvas/__tests__/textarea-layout.ts @@ -36,8 +36,8 @@ describe('textarea-layout', () => { ['Donaudampfsc', 'x2']); }); it('should wrap lines at -', () => { - layoutEqual(' Long text- message with sev lines.', - [' Long text-', 'message with','sev lines.']); + layoutEqual(' Long text- message with lines.', + [' Long text', '- message','with lines.']); }); it('should wrap lines at - 2', () => { layoutEqual('Long text- message with sev lines.', diff --git a/src/render/canvas/textarea-layout.ts b/src/render/canvas/textarea-layout.ts index 2942af6..6970005 100644 --- a/src/render/canvas/textarea-layout.ts +++ b/src/render/canvas/textarea-layout.ts @@ -13,7 +13,7 @@ export function layout(chars: string[], width: number, measure: (s: string, len: const lineWidth = measure(lineString, lineLen); pos.push([lineWidth - measure(chars[i], 1), line]); if (lineWidth > width) { - if (chars[i] === ' ' || chars[i] === '-') { + if (chars[i] === ' ') { let p = i; while (p > 0 && pos[p][1] === line && chars[p] === ' ') p--; for (let j = i; j > p; j--) { @@ -25,6 +25,10 @@ export function layout(chars: string[], width: number, measure: (s: string, len: pos.push([-1, line]); i++; } + } else if (chars[i] === '-') { + line++; + setLine(i, i + 1); + pos[i] = [0, line]; } else { let p = i; while (p > 0 && pos[p][1] === line && chars[p] !== ' ' && chars[p] !== '-') p--;