Skip to content

Commit

Permalink
fix(fabric.Textbox): Do not let splitbygrapheme split text previously…
Browse files Browse the repository at this point in the history
… unwrapped. (fabricjs#6621)

* fix(fabric.Textbox): The same text does not need to be wrapped

* fix(Lint): lint test case
  • Loading branch information
proYang authored and shanicerae committed Jan 16, 2021
1 parent 9f65200 commit 0ce486f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/shapes/textbox.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@
offset += word.length;

lineWidth += infixWidth + wordWidth - additionalSpace;
if (lineWidth >= desiredWidth && !lineJustStarted) {
if (lineWidth > desiredWidth && !lineJustStarted) {
graphemeLines.push(line);
line = [];
lineWidth = wordWidth;
Expand Down
14 changes: 14 additions & 0 deletions test/unit/textbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -516,4 +516,18 @@
assert.equal(textbox.styleHas('fontFamily', 1), true, 'style has fontFamily on line 1');
});

QUnit.test('The same text does not need to be wrapped.', function(assert) {
var str = '0123456789';
var measureTextbox = new fabric.Textbox(str, {
fontSize: 20,
splitByGrapheme: false,
});
var newTextbox = new fabric.Textbox(str, {
width: measureTextbox.width,
fontSize: 20,
splitByGrapheme: true,
});
assert.equal(newTextbox.textLines.length, measureTextbox.textLines.length, 'The same text is not wrapped');
});

})();

0 comments on commit 0ce486f

Please sign in to comment.