From 047d0f729b4d1e2074fe74148d19f69ed1e73f46 Mon Sep 17 00:00:00 2001 From: hyouuu Date: Mon, 29 Mar 2021 15:07:12 -0700 Subject: [PATCH] default color, Document.fromDelta, fix isItCut null check (#123) * default color, Document.fromDelta, fix isItCut null check * fix merge conflict --- lib/models/documents/document.dart | 4 ++++ lib/widgets/default_styles.dart | 3 +++ lib/widgets/raw_editor.dart | 6 ++++-- lib/widgets/text_line.dart | 9 +++++++-- 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/lib/models/documents/document.dart b/lib/models/documents/document.dart index 0ff76faf..8a620446 100644 --- a/lib/models/documents/document.dart +++ b/lib/models/documents/document.dart @@ -43,6 +43,10 @@ class Document { _loadDocument(_delta); } + Document.fromDelta(Delta delta) : _delta = delta { + _loadDocument(delta); + } + Delta insert(int index, Object? data) { assert(index >= 0); assert(data is String || data is Embeddable); diff --git a/lib/widgets/default_styles.dart b/lib/widgets/default_styles.dart index 5583307d..4f26d9d3 100644 --- a/lib/widgets/default_styles.dart +++ b/lib/widgets/default_styles.dart @@ -52,6 +52,7 @@ class DefaultStyles { final TextStyle? sizeLarge; // 'large' final TextStyle? sizeHuge; // 'huge' final TextStyle? link; + final Color? color; final DefaultTextBlockStyle? placeHolder; final DefaultTextBlockStyle? lists; final DefaultTextBlockStyle? quote; @@ -69,6 +70,7 @@ class DefaultStyles { this.underline, this.strikeThrough, this.link, + this.color, this.placeHolder, this.lists, this.quote, @@ -197,6 +199,7 @@ class DefaultStyles { underline: other.underline ?? underline, strikeThrough: other.strikeThrough ?? strikeThrough, link: other.link ?? link, + color: other.color ?? color, placeHolder: other.placeHolder ?? placeHolder, lists: other.lists ?? lists, quote: other.quote ?? quote, diff --git a/lib/widgets/raw_editor.dart b/lib/widgets/raw_editor.dart index 9d2a5fe4..130af8b4 100644 --- a/lib/widgets/raw_editor.dart +++ b/lib/widgets/raw_editor.dart @@ -1087,8 +1087,10 @@ class RawEditorState extends EditorState } Future __isItCut(TextEditingValue value) async { - final ClipboardData data = await (Clipboard.getData(Clipboard.kTextPlain) - as FutureOr); + ClipboardData? data = await Clipboard.getData(Clipboard.kTextPlain); + if (data == null) { + return false; + } return textEditingValue.text.length - value.text.length == data.text!.length; } diff --git a/lib/widgets/text_line.dart b/lib/widgets/text_line.dart index 0a9ef94e..0b6788cf 100644 --- a/lib/widgets/text_line.dart +++ b/lib/widgets/text_line.dart @@ -165,8 +165,13 @@ class TextLine extends StatelessWidget { Attribute? color = textNode.style.attributes[Attribute.color.key]; if (color != null && color.value != null) { - final textColor = stringToColor(color.value); - res = res.merge(TextStyle(color: textColor)); + var textColor = defaultStyles.color; + if (color.value is String) { + textColor = stringToColor(color.value); + } + if (textColor != null) { + res = res.merge(TextStyle(color: textColor)); + } } Attribute? background = textNode.style.attributes[Attribute.background.key];