fix: revert delta of bold

This commit is contained in:
Vincent Chan 2022-08-11 15:25:42 +08:00
parent 9c97a0b635
commit 8f6eb5a0d6
2 changed files with 13 additions and 9 deletions

View File

@ -15,7 +15,7 @@ Attributes invertAttributes(Attributes? attr, Attributes? base) {
return memo;
});
return attr.keys.fold(baseInverted, (memo, key) {
if (attr![key] != base![key] && base.containsKey(key)) {
if (attr![key] != base![key] && !base.containsKey(key)) {
memo[key] = null;
}
return memo;

View File

@ -230,14 +230,18 @@ void main() {
expect(expected, inverted);
expect(base.compose(delta).compose(inverted), base);
});
// test('retain', () {
// final delta = Delta().retain(2).retain(3, {'bold': true});
// final base = Delta().insert('123456');
// final expected = Delta().retain(2).retain(3, {'bold': null});
// final inverted = delta.invert(base);
// expect(expected, inverted);
// expect(base.compose(delta).compose(inverted), base);
// });
test('retain', () {
final delta = Delta()
..retain(2)
..retain(3, {'bold': true});
final base = Delta()..insert('123456');
final expected = Delta()
..retain(2)
..retain(3, {'bold': null});
final inverted = delta.invert(base);
expect(expected, inverted);
expect(base.compose(delta).compose(inverted), base);
});
});
group('json', () {
test('toJson()', () {