diff --git a/src/type/textCore.js b/src/type/textCore.js index 345267fa4c..c1f13531b8 100644 --- a/src/type/textCore.js +++ b/src/type/textCore.js @@ -1790,6 +1790,11 @@ function textCore(p5, fn) { return { bounds, lines }; }; + Renderer.prototype._trimEnd = function (str) { + // trim trailing linebreaks and whitespace only + return str.replace(/[\s\n]+$/, ''); + }; + /* Adjust width, height of bounds based on current rectMode * @private @@ -2247,13 +2252,13 @@ function textCore(p5, fn) { testLine = `${line + words[widx]}` + splitter; testWidth = this._textWidthSingle(testLine); if (line.length > 0 && testWidth > maxWidth) { - newLines.push(line.trim()); + newLines.push(this._trimEnd(line)); line = `${words[widx]}` + splitter; } else { line = testLine; } } - newLines.push(line.trim()); + newLines.push(this._trimEnd(line)); } return newLines; }; diff --git a/test/manual-test-examples/type/one-off.html b/test/manual-test-examples/type/one-off.html new file mode 100644 index 0000000000..8a31bcf693 --- /dev/null +++ b/test/manual-test-examples/type/one-off.html @@ -0,0 +1,223 @@ + + + + + + + + + + + + + + + \ No newline at end of file