Add isEmpty method for Document class

pull/37/head^2
singerdmx 4 years ago
parent 59410649db
commit a3ee421d1a
  1. 14
      lib/models/documents/document.dart
  2. 55
      lib/widgets/raw_editor.dart

@ -237,6 +237,20 @@ class Document {
_root.remove(node);
}
}
bool isEmpty() {
if (root.children.length != 1) {
return false;
}
final Node node = root.children.first;
if (!node.isLast) {
return false;
}
Delta delta = node.toDelta();
return delta.length == 1 && delta.first.data == '\n';
}
}
enum ChangeSource {

@ -503,13 +503,15 @@ class RawEditorState extends EditorState
_focusAttachment.reparent();
super.build(context);
Document _doc = widget.controller.document;
Widget child = CompositedTransformTarget(
link: _toolbarLayerLink,
child: Semantics(
child: _Editor(
key: _editorKey,
children: _buildChildren(context),
document: widget.controller.document,
children: _buildChildren(_doc, context),
document: _doc,
selection: widget.controller.selection,
hasFocus: _hasFocus,
textDirection: _textDirection,
@ -562,30 +564,13 @@ class RawEditorState extends EditorState
requestKeyboard();
}
_buildChildren(BuildContext context) {
_buildChildren(Document doc, BuildContext context) {
final result = <Widget>[];
Map<int, int> indentLevelCounts = {};
for (Node node in widget.controller.document.root.children) {
for (Node node in doc.root.children) {
if (node is Line) {
TextLine textLine = TextLine(
line: node,
textDirection: _textDirection,
embedBuilder: widget.embedBuilder,
styles: _styles,
);
EditableTextLine editableTextLine = EditableTextLine(
node,
null,
textLine,
0,
_getVerticalSpacingForLine(node, _styles),
_textDirection,
widget.controller.selection,
widget.selectionColor,
widget.enableInteractiveSelection,
_hasFocus,
MediaQuery.of(context).devicePixelRatio,
_cursorCont);
EditableTextLine editableTextLine =
_getEditableTextLineFromNode(node, context);
result.add(editableTextLine);
} else if (node is Block) {
Map<String, Attribute> attrs = node.style.attributes;
@ -612,6 +597,30 @@ class RawEditorState extends EditorState
return result;
}
EditableTextLine _getEditableTextLineFromNode(
Line node, BuildContext context) {
TextLine textLine = TextLine(
line: node,
textDirection: _textDirection,
embedBuilder: widget.embedBuilder,
styles: _styles,
);
EditableTextLine editableTextLine = EditableTextLine(
node,
null,
textLine,
0,
_getVerticalSpacingForLine(node, _styles),
_textDirection,
widget.controller.selection,
widget.selectionColor,
widget.enableInteractiveSelection,
_hasFocus,
MediaQuery.of(context).devicePixelRatio,
_cursorCont);
return editableTextLine;
}
Tuple2<double, double> _getVerticalSpacingForLine(
Line line, DefaultStyles defaultStyles) {
Map<String, Attribute> attrs = line.style.attributes;

Loading…
Cancel
Save