From 15bd6f2342bbc8b988a627c86f6bcf9d773ca848 Mon Sep 17 00:00:00 2001 From: Xun Gong Date: Wed, 1 Sep 2021 13:09:20 -0700 Subject: [PATCH 1/3] Add "small" (extended) markdown style support --- lib/src/models/documents/attribute.dart | 8 ++++++++ lib/src/widgets/default_styles.dart | 4 ++++ lib/src/widgets/text_line.dart | 1 + lib/src/widgets/toolbar.dart | 9 +++++++++ 4 files changed, 22 insertions(+) diff --git a/lib/src/models/documents/attribute.dart b/lib/src/models/documents/attribute.dart index 97d82f15..467742d5 100644 --- a/lib/src/models/documents/attribute.dart +++ b/lib/src/models/documents/attribute.dart @@ -19,6 +19,7 @@ class Attribute { static final Map _registry = LinkedHashMap.of({ Attribute.bold.key: Attribute.bold, Attribute.italic.key: Attribute.italic, + Attribute.small.key: Attribute.small, Attribute.underline.key: Attribute.underline, Attribute.strikeThrough.key: Attribute.strikeThrough, Attribute.font.key: Attribute.font, @@ -43,6 +44,8 @@ class Attribute { static final ItalicAttribute italic = ItalicAttribute(); + static final SmallAttribute small = SmallAttribute(); + static final UnderlineAttribute underline = UnderlineAttribute(); static final StrikeThroughAttribute strikeThrough = StrikeThroughAttribute(); @@ -82,6 +85,7 @@ class Attribute { static final Set inlineKeys = { Attribute.bold.key, Attribute.italic.key, + Attribute.small.key, Attribute.underline.key, Attribute.strikeThrough.key, Attribute.link.key, @@ -217,6 +221,10 @@ class ItalicAttribute extends Attribute { ItalicAttribute() : super('italic', AttributeScope.INLINE, true); } +class SmallAttribute extends Attribute { + SmallAttribute() : super('small', AttributeScope.INLINE, true); +} + class UnderlineAttribute extends Attribute { UnderlineAttribute() : super('underline', AttributeScope.INLINE, true); } diff --git a/lib/src/widgets/default_styles.dart b/lib/src/widgets/default_styles.dart index 1cebe135..ca00cf19 100644 --- a/lib/src/widgets/default_styles.dart +++ b/lib/src/widgets/default_styles.dart @@ -51,6 +51,7 @@ class DefaultStyles { this.paragraph, this.bold, this.italic, + this.small, this.underline, this.strikeThrough, this.link, @@ -73,6 +74,7 @@ class DefaultStyles { final DefaultTextBlockStyle? paragraph; final TextStyle? bold; final TextStyle? italic; + final TextStyle? small; final TextStyle? underline; final TextStyle? strikeThrough; final TextStyle? sizeSmall; // 'small' @@ -147,6 +149,7 @@ class DefaultStyles { baseStyle, const Tuple2(0, 0), const Tuple2(0, 0), null), bold: const TextStyle(fontWeight: FontWeight.bold), italic: const TextStyle(fontStyle: FontStyle.italic), + small: const TextStyle(fontSize: 12), underline: const TextStyle(decoration: TextDecoration.underline), strikeThrough: const TextStyle(decoration: TextDecoration.lineThrough), link: TextStyle( @@ -205,6 +208,7 @@ class DefaultStyles { paragraph: other.paragraph ?? paragraph, bold: other.bold ?? bold, italic: other.italic ?? italic, + small: other.small ?? small, underline: other.underline ?? underline, strikeThrough: other.strikeThrough ?? strikeThrough, link: other.link ?? link, diff --git a/lib/src/widgets/text_line.dart b/lib/src/widgets/text_line.dart index 44715f6e..6da21a4c 100644 --- a/lib/src/widgets/text_line.dart +++ b/lib/src/widgets/text_line.dart @@ -181,6 +181,7 @@ class TextLine extends StatelessWidget { { Attribute.bold.key: defaultStyles.bold, Attribute.italic.key: defaultStyles.italic, + Attribute.small.key: defaultStyles.small, Attribute.link.key: defaultStyles.link, Attribute.underline.key: defaultStyles.underline, Attribute.strikeThrough.key: defaultStyles.strikeThrough, diff --git a/lib/src/widgets/toolbar.dart b/lib/src/widgets/toolbar.dart index dff2013c..2803948d 100644 --- a/lib/src/widgets/toolbar.dart +++ b/lib/src/widgets/toolbar.dart @@ -65,6 +65,7 @@ class QuillToolbar extends StatelessWidget implements PreferredSizeWidget { double toolbarIconSize = kDefaultIconSize, bool showBoldButton = true, bool showItalicButton = true, + bool showSmallButton = false, bool showUnderLineButton = true, bool showStrikeThrough = true, bool showColorButton = true, @@ -96,6 +97,7 @@ class QuillToolbar extends StatelessWidget implements PreferredSizeWidget { showHistory || showBoldButton || showItalicButton || + showSmallButton || showUnderLineButton || showStrikeThrough || showColorButton || @@ -142,6 +144,13 @@ class QuillToolbar extends StatelessWidget implements PreferredSizeWidget { iconSize: toolbarIconSize, controller: controller, ), + if (showSmallButton) + ToggleStyleButton( + attribute: Attribute.small, + icon: Icons.format_size, + iconSize: toolbarIconSize, + controller: controller, + ), if (showUnderLineButton) ToggleStyleButton( attribute: Attribute.underline, From 3378ddff5773f5a36b597574fa8fed6b25b169eb Mon Sep 17 00:00:00 2001 From: Xun Gong Date: Wed, 1 Sep 2021 18:54:22 -0700 Subject: [PATCH 2/3] Revert caret position change which breaks its position --- lib/src/widgets/cursor.dart | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/lib/src/widgets/cursor.dart b/lib/src/widgets/cursor.dart index 2d13aff0..427158d2 100644 --- a/lib/src/widgets/cursor.dart +++ b/lib/src/widgets/cursor.dart @@ -246,18 +246,8 @@ class CursorPainter { /// [offset] is global top left (x, y) of text line /// [position] is relative (x) in text line void paint(Canvas canvas, Offset offset, TextPosition position) { - // relative (x, y) to global offset - var relativeCaretOffset = editable!.getOffsetForCaret(position, prototype); - if (relativeCaretOffset == Offset.zero) { - relativeCaretOffset = editable!.getOffsetForCaret( - TextPosition( - offset: position.offset - 1, affinity: position.affinity), - prototype); - // Hardcoded 6 as estimate of the width of a character - relativeCaretOffset = - Offset(relativeCaretOffset.dx + 6, relativeCaretOffset.dy); - } - final caretOffset = relativeCaretOffset + offset; + final caretOffset = + editable!.getOffsetForCaret(position, prototype) + offset;; var caretRect = prototype.shift(caretOffset); if (style.offset != null) { caretRect = caretRect.shift(style.offset!); From 8945379379daa95c6714f69e5fbcaf2243e359b5 Mon Sep 17 00:00:00 2001 From: Xun Gong Date: Wed, 1 Sep 2021 18:59:19 -0700 Subject: [PATCH 3/3] Default small text to dark gray color --- lib/src/widgets/default_styles.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/widgets/default_styles.dart b/lib/src/widgets/default_styles.dart index ca00cf19..8f36fac1 100644 --- a/lib/src/widgets/default_styles.dart +++ b/lib/src/widgets/default_styles.dart @@ -149,7 +149,7 @@ class DefaultStyles { baseStyle, const Tuple2(0, 0), const Tuple2(0, 0), null), bold: const TextStyle(fontWeight: FontWeight.bold), italic: const TextStyle(fontStyle: FontStyle.italic), - small: const TextStyle(fontSize: 12), + small: const TextStyle(fontSize: 12, color: Colors.black45), underline: const TextStyle(decoration: TextDecoration.underline), strikeThrough: const TextStyle(decoration: TextDecoration.lineThrough), link: TextStyle(