fix: import single line delta failed

This commit is contained in:
Lucas.Xu 2023-08-10 16:15:27 +08:00
commit 016e141f51
2 changed files with 16 additions and 1 deletions

View file

@ -63,6 +63,10 @@ class QuillDeltaEncoder extends Converter<Delta, Document> {
} }
} }
if (index == 0) {
document.insert([index], [node]);
}
return document; return document;
} }

View file

@ -5,11 +5,22 @@ import 'package:flutter_test/flutter_test.dart';
void main() async { void main() async {
group('delta_document_encoder.dart', () { group('delta_document_encoder.dart', () {
test('', () { test('built-in json', () {
final json = jsonDecode(quillDeltaSample.replaceAll('\\\\\n', '\\n')); final json = jsonDecode(quillDeltaSample.replaceAll('\\\\\n', '\\n'));
final document = quillDeltaEncoder.convert(Delta.fromJson(json)); final document = quillDeltaEncoder.convert(Delta.fromJson(json));
expect(jsonEncode(document.toJson()), documentSample); expect(jsonEncode(document.toJson()), documentSample);
}); });
test('issues 356', () {
const plainText =
'How many digits are there in the smallest number which is composed entirely of fives (e.g.5555) and which is divisible by 99?';
final json = jsonDecode(
'[{"insert": "$plainText"}]',
);
final document = quillDeltaEncoder.convert(Delta.fromJson(json));
expect(document.root.children.length, 1);
expect(document.nodeAtPath([0])!.delta!.toPlainText(), plainText);
});
}); });
} }