Update text_line for handling Embed

pull/324/head
Xin Yao 4 years ago
parent 2195c4ae3e
commit 6aaf351277
  1. 6
      lib/src/models/documents/nodes/line.dart
  2. 17
      lib/src/widgets/text_line.dart

@ -26,11 +26,7 @@ class Line extends Container<Leaf?> {
/// Returns `true` if this line contains an embedded object. /// Returns `true` if this line contains an embedded object.
bool get hasEmbed { bool get hasEmbed {
if (childCount != 1) { return children.any((child) => child is Embed);
return false;
}
return children.single is Embed;
} }
/// Returns next [Line] or `null` if this is the last line in the document. /// Returns next [Line] or `null` if this is the last line in the document.

@ -39,12 +39,17 @@ class TextLine extends StatelessWidget {
Widget build(BuildContext context) { Widget build(BuildContext context) {
assert(debugCheckHasMediaQuery(context)); assert(debugCheckHasMediaQuery(context));
// In rare circumstances, the line could contain an Embed & a Text of if (line.hasEmbed) {
// newline, which is unexpected and probably we should find out the if (line.childCount == 1) {
// root cause // For video, it is always single child
final childCount = line.childCount; final embed = line.children.single as Embed;
if (line.hasEmbed || (childCount > 1 && line.children.first is Embed)) { return EmbedProxy(embedBuilder(context, embed, readOnly));
final embed = line.children.first as Embed; }
// The line could contain more than one Embed & more than one Text
// TODO: handle more than one Embed
final embed =
line.children.firstWhere((child) => child is Embed) as Embed;
return EmbedProxy(embedBuilder(context, embed, readOnly)); return EmbedProxy(embedBuilder(context, embed, readOnly));
} }

Loading…
Cancel
Save