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 memo;
}); });
return attr.keys.fold(baseInverted, (memo, key) { 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; memo[key] = null;
} }
return memo; return memo;

View File

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