Skip to content

Commit

Permalink
include textBackgroundColor check in hasStyleChanged (fabricjs#8365)
Browse files Browse the repository at this point in the history
* include textBackgroundColor check in hasStyleChanged

* fix assert message and add changelog entry
  • Loading branch information
jakesjews authored and frankrousseau committed Jan 6, 2023
1 parent 20ef561 commit 84c6476
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## [next]

- fix(textStyles): Handle style objects with only a textBackgroundColor property in stylesToArray [#8365](https://github.com/fabricjs/fabric.js/pull/8365)
- chore(): fix typos in intersection file [#8345](https://github.com/fabricjs/fabric.js/pull/8345)
- fix(textStyles): Handle empty style object in stylesToArray [#8357](https://github.com/fabricjs/fabric.js/pull/8357)
- ci(build): safeguard concurrent unlocking [#8309](https://github.com/fabricjs/fabric.js/pull/8309)
Expand Down
1 change: 1 addition & 0 deletions src/util/misc/textStyles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export const hasStyleChanged = (
prevStyle.fontFamily !== thisStyle.fontFamily ||
prevStyle.fontWeight !== thisStyle.fontWeight ||
prevStyle.fontStyle !== thisStyle.fontStyle ||
prevStyle.textBackgroundColor !== thisStyle.textBackgroundColor ||
prevStyle.deltaY !== thisStyle.deltaY ||
(forTextSpans &&
(prevStyle.overline !== thisStyle.overline ||
Expand Down
11 changes: 11 additions & 0 deletions test/unit/text.js
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,17 @@
assert.deepEqual(obj.styles, [], 'empty style object has been removed');
});

QUnit.test('text toObject can handle style objects with only a textBackgroundColor property', function(assert) {
var text = new fabric.Text('xxx');
text.styles = { 0: { 0: { textBackgroundColor: 'blue' } } };
var obj = text.toObject();
assert.deepEqual(
obj.styles,
[{ start: 0, end: 1, style: { textBackgroundColor: 'blue' }}],
'styles with only a textBackgroundColor property do not throw an error'
);
});

QUnit.test('getFontCache works with fontWeight numbers', function(assert) {
var text = new fabric.Text('xxx', { fontWeight: 400 });
text.initDimensions();
Expand Down

0 comments on commit 84c6476

Please sign in to comment.