diff --git a/lib/widgets/default_styles.dart b/lib/widgets/default_styles.dart index 014fe486..b9116489 100644 --- a/lib/widgets/default_styles.dart +++ b/lib/widgets/default_styles.dart @@ -2,10 +2,10 @@ import 'package:flutter/material.dart'; import 'package:flutter/widgets.dart'; import 'package:tuple/tuple.dart'; -class QuillTheme extends InheritedWidget { +class QuillStyles extends InheritedWidget { final DefaultStyles data; - QuillTheme({ + QuillStyles({ Key key, @required this.data, @required Widget child, @@ -14,12 +14,12 @@ class QuillTheme extends InheritedWidget { super(key: key, child: child); @override - bool updateShouldNotify(QuillTheme oldWidget) { + bool updateShouldNotify(QuillStyles oldWidget) { return data != oldWidget.data; } - static DefaultStyles of(BuildContext context, nullOk) { - var widget = context.dependOnInheritedWidgetOfExactType(); + static DefaultStyles getStyles(BuildContext context, nullOk) { + var widget = context.dependOnInheritedWidgetOfExactType(); if (widget == null && nullOk) { return null; } @@ -157,4 +157,20 @@ class DefaultStyles { borderRadius: BorderRadius.circular(2), ))); } + + DefaultStyles merge(DefaultStyles other) { + return DefaultStyles( + other.h1 ?? this.h1, + other.h2 ?? this.h2, + other.h3 ?? this.h3, + other.paragraph ?? this.paragraph, + other.bold ?? this.bold, + other.italic ?? this.italic, + other.underline ?? this.underline, + other.strikeThrough ?? this.strikeThrough, + other.link ?? this.link, + other.lists ?? this.lists, + other.quote ?? this.quote, + other.code ?? this.code); + } } diff --git a/lib/widgets/editor.dart b/lib/widgets/editor.dart index 4327c7e4..a983ad8e 100644 --- a/lib/widgets/editor.dart +++ b/lib/widgets/editor.dart @@ -9,6 +9,7 @@ import 'package:flutter_quill/models/documents/nodes/container.dart' as container; import 'package:flutter_quill/models/documents/nodes/node.dart'; import 'package:flutter_quill/utils/diff_delta.dart'; +import 'package:flutter_quill/widgets/default_styles.dart'; import 'package:flutter_quill/widgets/text_selection.dart'; import 'box.dart'; @@ -324,6 +325,8 @@ class RawEditorState extends EditorState CursorCont _cursorCont; ScrollController _scrollController; KeyboardListener _keyboardListener; + bool _didAutoFocus = false; + DefaultStyles _styles; final ClipboardStatusNotifier _clipboardStatus = ClipboardStatusNotifier(); bool get _hasFocus => widget.focusNode.hasFocus; @@ -736,7 +739,17 @@ class RawEditorState extends EditorState @override didChangeDependencies() { - // TODO + super.didChangeDependencies(); + DefaultStyles parentStyles = QuillStyles.getStyles(context, true); + DefaultStyles defaultStyles = DefaultStyles.getInstance(context); + _styles = (parentStyles != null) + ? defaultStyles.merge(parentStyles) + : defaultStyles; + + if (!_didAutoFocus && widget.autoFocus) { + FocusScope.of(context).autofocus(widget.focusNode); + _didAutoFocus = true; + } } @override