Merge branch 'singerdmx:master' into master

pull/382/head
Aldy J 5 years ago committed by GitHub
commit aa0b990b77
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      lib/src/models/documents/attribute.dart
  2. 14
      lib/src/widgets/cursor.dart
  3. 4
      lib/src/widgets/default_styles.dart
  4. 1
      lib/src/widgets/text_line.dart
  5. 9
      lib/src/widgets/toolbar.dart

@ -19,6 +19,7 @@ class Attribute<T> {
static final Map<String, Attribute> _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<T> {
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<T> {
static final Set<String> 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<bool> {
ItalicAttribute() : super('italic', AttributeScope.INLINE, true);
}
class SmallAttribute extends Attribute<bool> {
SmallAttribute() : super('small', AttributeScope.INLINE, true);
}
class UnderlineAttribute extends Attribute<bool> {
UnderlineAttribute() : super('underline', AttributeScope.INLINE, true);
}

@ -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!);

@ -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, color: Colors.black45),
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,

@ -181,6 +181,7 @@ class TextLine extends StatelessWidget {
<String, TextStyle?>{
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,

@ -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,

Loading…
Cancel
Save