Improve font size button

pull/1578/head
Ellet 1 year ago
parent f8fc9d874c
commit 03610e9a87
No known key found for this signature in database
GPG Key ID: C488CC70BBCEF0D1
  1. 2
      CHANGELOG.md
  2. 7
      flutter_quill_extensions/CHANGELOG.md
  3. 2
      flutter_quill_extensions/pubspec.yaml
  4. 7
      flutter_quill_test/CHANGELOG.md
  5. 2
      flutter_quill_test/pubspec.yaml
  6. 27
      lib/src/models/config/toolbar/buttons/font_size_configurations.dart
  7. 10
      lib/src/widgets/quill/quill_controller.dart
  8. 15
      lib/src/widgets/raw_editor/raw_editor_state_text_input_client_mixin.dart
  9. 4
      lib/src/widgets/toolbar/buttons/font_family_button.dart
  10. 69
      lib/src/widgets/toolbar/buttons/font_size_button.dart
  11. 7
      packages/quill_html_converter/CHANGELOG.md
  12. 2
      packages/quill_html_converter/pubspec.yaml
  13. 2
      pubspec.yaml

@ -7,7 +7,7 @@ All notable changes to this project will be documented in this file.
* Update `README.md` and the doc * Update `README.md` and the doc
* Dispose the `QuillToolbarSelectHeaderStyleButton` state listener in `dispose` * Dispose the `QuillToolbarSelectHeaderStyleButton` state listener in `dispose`
* Upgrade the font family button to material 3 * Upgrade the font family button to material 3
* Rework the font family functionallity to change the font once and type all over the editor * Rework the font family and font size functionallities to change the font once and type all over the editor
## 9.0.0-dev-8 ## 9.0.0-dev-8
* Better support for pasting HTML contents from external websites to the editor * Better support for pasting HTML contents from external websites to the editor

@ -2,6 +2,13 @@
All notable changes to this project will be documented in this file. All notable changes to this project will be documented in this file.
## 9.0.0-dev-9
* Improves the new logic of pasting HTML contents into the Editor
* Update `README.md` and the doc
* Dispose the `QuillToolbarSelectHeaderStyleButton` state listener in `dispose`
* Upgrade the font family button to material 3
* Rework the font family and font size functionallities to change the font once and type all over the editor
## 9.0.0-dev-8 ## 9.0.0-dev-8
* Better support for pasting HTML contents from external websites to the editor * Better support for pasting HTML contents from external websites to the editor
* The experimental support of converting the HTML from `quill_html_converter` is now built-in in the `flutter_quill` and removed from there (Breaking change for `quill_html_converter`) * The experimental support of converting the HTML from `quill_html_converter` is now built-in in the `flutter_quill` and removed from there (Breaking change for `quill_html_converter`)

@ -1,6 +1,6 @@
name: flutter_quill_extensions name: flutter_quill_extensions
description: Embed extensions for flutter_quill including image, video, formula and etc. description: Embed extensions for flutter_quill including image, video, formula and etc.
version: 9.0.0-dev-8 version: 9.0.0-dev-9
homepage: https://github.com/singerdmx/flutter-quill/tree/master/flutter_quill_extensions/ homepage: https://github.com/singerdmx/flutter-quill/tree/master/flutter_quill_extensions/
repository: https://github.com/singerdmx/flutter-quill/tree/master/flutter_quill_extensions/ repository: https://github.com/singerdmx/flutter-quill/tree/master/flutter_quill_extensions/
issue_tracker: https://github.com/singerdmx/flutter-quill/issues/ issue_tracker: https://github.com/singerdmx/flutter-quill/issues/

@ -2,6 +2,13 @@
All notable changes to this project will be documented in this file. All notable changes to this project will be documented in this file.
## 9.0.0-dev-9
* Improves the new logic of pasting HTML contents into the Editor
* Update `README.md` and the doc
* Dispose the `QuillToolbarSelectHeaderStyleButton` state listener in `dispose`
* Upgrade the font family button to material 3
* Rework the font family and font size functionallities to change the font once and type all over the editor
## 9.0.0-dev-8 ## 9.0.0-dev-8
* Better support for pasting HTML contents from external websites to the editor * Better support for pasting HTML contents from external websites to the editor
* The experimental support of converting the HTML from `quill_html_converter` is now built-in in the `flutter_quill` and removed from there (Breaking change for `quill_html_converter`) * The experimental support of converting the HTML from `quill_html_converter` is now built-in in the `flutter_quill` and removed from there (Breaking change for `quill_html_converter`)

@ -1,6 +1,6 @@
name: flutter_quill_test name: flutter_quill_test
description: Test utilities for flutter_quill which includes methods to simplify interacting with the editor in test cases. description: Test utilities for flutter_quill which includes methods to simplify interacting with the editor in test cases.
version: 9.0.0-dev-8 version: 9.0.0-dev-9
homepage: https://github.com/singerdmx/flutter-quill/tree/master/flutter_quill_test/ homepage: https://github.com/singerdmx/flutter-quill/tree/master/flutter_quill_test/
repository: https://github.com/singerdmx/flutter-quill/tree/master/flutter_quill_test/ repository: https://github.com/singerdmx/flutter-quill/tree/master/flutter_quill_test/
issue_tracker: https://github.com/singerdmx/flutter-quill/issues/ issue_tracker: https://github.com/singerdmx/flutter-quill/issues/

@ -2,13 +2,18 @@ import 'dart:ui';
import 'package:flutter/foundation.dart' show immutable; import 'package:flutter/foundation.dart' show immutable;
import 'package:flutter/material.dart' import 'package:flutter/material.dart'
show Colors, PopupMenuEntry, ValueChanged; show ButtonStyle, Colors, PopupMenuEntry, ValueChanged;
import 'package:flutter/widgets.dart' import 'package:flutter/widgets.dart'
show Color, EdgeInsets, EdgeInsetsGeometry, TextOverflow, TextStyle; show
Color,
EdgeInsets,
EdgeInsetsGeometry,
OutlinedBorder,
TextOverflow,
TextStyle;
import '../../../../widgets/quill/quill_controller.dart'; import '../../../../widgets/quill/quill_controller.dart';
import '../../../documents/attribute.dart'; import '../../../documents/attribute.dart';
import '../../../themes/quill_icon_theme.dart';
import '../../quill_configurations.dart'; import '../../quill_configurations.dart';
class QuillToolbarFontSizeButtonExtraOptions class QuillToolbarFontSizeButtonExtraOptions
@ -31,12 +36,8 @@ class QuillToolbarFontSizeButtonOptions extends QuillToolbarBaseButtonOptions<
const QuillToolbarFontSizeButtonOptions({ const QuillToolbarFontSizeButtonOptions({
this.iconSize, this.iconSize,
this.iconButtonFactor, this.iconButtonFactor,
this.fillColor,
this.hoverElevation = 1,
this.highlightElevation = 1,
this.rawItemsMap, this.rawItemsMap,
this.onSelected, this.onSelected,
super.iconTheme,
this.attribute = Attribute.size, this.attribute = Attribute.size,
super.controller, super.controller,
super.afterButtonPressed, super.afterButtonPressed,
@ -50,13 +51,13 @@ class QuillToolbarFontSizeButtonOptions extends QuillToolbarBaseButtonOptions<
this.itemPadding, this.itemPadding,
this.defaultItemColor = Colors.red, this.defaultItemColor = Colors.red,
super.childBuilder, super.childBuilder,
this.shape,
}); });
final double? iconSize; final double? iconSize;
final double? iconButtonFactor; final double? iconButtonFactor;
final Color? fillColor;
final double hoverElevation; final ButtonStyle? shape;
final double highlightElevation;
/// By default it will be [fontSizesValues] from [QuillSimpleToolbarConfigurations] /// By default it will be [fontSizesValues] from [QuillSimpleToolbarConfigurations]
/// You can override this if you want /// You can override this if you want
@ -92,15 +93,12 @@ class QuillToolbarFontSizeButtonOptions extends QuillToolbarBaseButtonOptions<
Color? defaultItemColor, Color? defaultItemColor,
VoidCallback? afterButtonPressed, VoidCallback? afterButtonPressed,
String? tooltip, String? tooltip,
QuillIconTheme? iconTheme,
QuillController? controller, QuillController? controller,
OutlinedBorder? shape,
}) { }) {
return QuillToolbarFontSizeButtonOptions( return QuillToolbarFontSizeButtonOptions(
iconSize: iconSize ?? this.iconSize, iconSize: iconSize ?? this.iconSize,
iconButtonFactor: iconButtonFactor ?? this.iconButtonFactor, iconButtonFactor: iconButtonFactor ?? this.iconButtonFactor,
fillColor: fillColor ?? this.fillColor,
hoverElevation: hoverElevation ?? this.hoverElevation,
highlightElevation: highlightElevation ?? this.highlightElevation,
rawItemsMap: rawItemsMap ?? this.rawItemsMap, rawItemsMap: rawItemsMap ?? this.rawItemsMap,
onSelected: onSelected ?? this.onSelected, onSelected: onSelected ?? this.onSelected,
attribute: attribute ?? this.attribute, attribute: attribute ?? this.attribute,
@ -113,7 +111,6 @@ class QuillToolbarFontSizeButtonOptions extends QuillToolbarBaseButtonOptions<
itemPadding: itemPadding ?? this.itemPadding, itemPadding: itemPadding ?? this.itemPadding,
defaultItemColor: defaultItemColor ?? this.defaultItemColor, defaultItemColor: defaultItemColor ?? this.defaultItemColor,
tooltip: tooltip ?? super.tooltip, tooltip: tooltip ?? super.tooltip,
iconTheme: iconTheme ?? super.iconTheme,
afterButtonPressed: afterButtonPressed ?? super.afterButtonPressed, afterButtonPressed: afterButtonPressed ?? super.afterButtonPressed,
controller: controller ?? super.controller, controller: controller ?? super.controller,
); );

@ -63,10 +63,18 @@ class QuillController extends ChangeNotifier {
String? _selectedFontFamily; String? _selectedFontFamily;
String? get selectedFontFamily => _selectedFontFamily; String? get selectedFontFamily => _selectedFontFamily;
void selectFontFamily(String newFontFamily) { void selectFontFamily(String? newFontFamily) {
_selectedFontFamily = newFontFamily; _selectedFontFamily = newFontFamily;
} }
/// The current font size, null to use the default one
String? _selectedFontSize;
String? get selectedFontSize => _selectedFontSize;
void selectFontSize(String? newFontSize) {
_selectedFontSize = newFontSize;
}
/// Tells whether to keep or reset the [toggledStyle] /// Tells whether to keep or reset the [toggledStyle]
/// when user adds a new line. /// when user adds a new line.
final bool _keepStyleOnNewLine; final bool _keepStyleOnNewLine;

@ -10,6 +10,7 @@ import 'package:flutter/services.dart';
import '../../models/documents/attribute.dart'; import '../../models/documents/attribute.dart';
import '../../models/documents/document.dart'; import '../../models/documents/document.dart';
import '../../utils/delta.dart'; import '../../utils/delta.dart';
import '../../utils/font.dart';
import '../editor/editor.dart'; import '../editor/editor.dart';
import 'raw_editor.dart'; import 'raw_editor.dart';
@ -216,6 +217,20 @@ mixin RawEditorStateTextInputClientMixin on EditorState
), ),
); );
} }
if (widget.configurations.controller.selectedFontSize != null) {
widget.configurations.controller.formatText(
diff.start,
diff.deleted.length,
Attribute.fromKeyValue(
Attribute.size.key,
widget.configurations.controller.selectedFontSize == '0'
? null
: getFontSize(
widget.configurations.controller.selectedFontSize),
),
);
}
} }
} }

@ -5,7 +5,6 @@ import '../../../extensions/quill_configurations_ext.dart';
import '../../../l10n/extensions/localizations.dart'; import '../../../l10n/extensions/localizations.dart';
import '../../../models/config/toolbar/buttons/font_family_configurations.dart'; import '../../../models/config/toolbar/buttons/font_family_configurations.dart';
import '../../../models/documents/attribute.dart'; import '../../../models/documents/attribute.dart';
import '../../../models/documents/style.dart';
import '../../../models/themes/quill_icon_theme.dart'; import '../../../models/themes/quill_icon_theme.dart';
import '../../quill/quill_controller.dart'; import '../../quill/quill_controller.dart';
@ -226,6 +225,7 @@ class QuillToolbarFontFamilyButtonState
padding: options.itemPadding, padding: options.itemPadding,
onTap: () { onTap: () {
if (fontFamily.value == 'Clear') { if (fontFamily.value == 'Clear') {
controller.selectFontFamily(null);
return; return;
} }
controller.selectFontFamily(fontFamily.value); controller.selectFontFamily(fontFamily.value);
@ -256,6 +256,8 @@ class QuillToolbarFontFamilyButtonState
setState(() { setState(() {
if (keyName != 'Clear') { if (keyName != 'Clear') {
_currentValue = keyName ?? _defaultDisplayText; _currentValue = keyName ?? _defaultDisplayText;
} else {
_currentValue = _defaultDisplayText;
} }
if (keyName != null) { if (keyName != null) {
controller.formatSelection( controller.formatSelection(

@ -57,47 +57,17 @@ class QuillToolbarFontSizeButtonState
return options.initialValue ?? widget.defaultDisplayText; return options.initialValue ?? widget.defaultDisplayText;
} }
Style get _selectionStyle => controller.getSelectionStyle();
@override @override
void initState() { void initState() {
super.initState(); super.initState();
_initState();
}
void _initState() {
_currentValue = _defaultDisplayText; _currentValue = _defaultDisplayText;
controller.addListener(_didChangeEditingValue);
} }
@override @override
void dispose() { void dispose() {
controller.removeListener(_didChangeEditingValue);
super.dispose(); super.dispose();
} }
@override
void didUpdateWidget(covariant QuillToolbarFontSizeButton oldWidget) {
super.didUpdateWidget(oldWidget);
if (controller == oldWidget.controller) {
return;
}
controller
..removeListener(_didChangeEditingValue)
..addListener(_didChangeEditingValue);
}
void _didChangeEditingValue() {
final attribute = _selectionStyle.attributes[options.attribute.key];
if (attribute == null) {
setState(() => _currentValue = _defaultDisplayText);
return;
}
final keyName = _getKeyName(attribute.value);
setState(() => _currentValue = keyName ?? _defaultDisplayText);
}
String? _getKeyName(dynamic value) { String? _getKeyName(dynamic value) {
for (final entry in rawItemsMap.entries) { for (final entry in rawItemsMap.entries) {
if (getFontSize(entry.value) == getFontSize(value)) { if (getFontSize(entry.value) == getFontSize(value)) {
@ -157,7 +127,6 @@ class QuillToolbarFontSizeButtonState
tooltip: tooltip, tooltip: tooltip,
iconSize: iconSize, iconSize: iconSize,
iconButtonFactor: iconButtonFactor, iconButtonFactor: iconButtonFactor,
iconTheme: iconTheme,
afterButtonPressed: afterButtonPressed, afterButtonPressed: afterButtonPressed,
controller: controller, controller: controller,
), ),
@ -177,17 +146,18 @@ class QuillToolbarFontSizeButtonState
), ),
child: UtilityWidgets.maybeTooltip( child: UtilityWidgets.maybeTooltip(
message: tooltip, message: tooltip,
child: RawMaterialButton( child: IconButton(
visualDensity: VisualDensity.compact, visualDensity: VisualDensity.compact,
shape: RoundedRectangleBorder( style: IconButton.styleFrom(
borderRadius: BorderRadius.circular(iconTheme?.borderRadius ?? 2), shape: iconTheme?.borderRadius != null
? RoundedRectangleBorder(
borderRadius:
BorderRadius.circular(iconTheme?.borderRadius ?? -1),
)
: null,
), ),
fillColor: options.fillColor,
elevation: 0,
hoverElevation: options.hoverElevation,
highlightElevation: options.hoverElevation,
onPressed: _onPressed, onPressed: _onPressed,
child: _buildContent(context), icon: _buildContent(context),
), ),
), ),
); );
@ -215,6 +185,13 @@ class QuillToolbarFontSizeButtonState
value: fontSize.value, value: fontSize.value,
height: options.itemHeight ?? kMinInteractiveDimension, height: options.itemHeight ?? kMinInteractiveDimension,
padding: options.itemPadding, padding: options.itemPadding,
onTap: () {
if (fontSize.value == '0') {
controller.selectFontSize(null);
return;
}
controller.selectFontSize(fontSize.value);
},
child: Text( child: Text(
fontSize.key.toString(), fontSize.key.toString(),
style: TextStyle( style: TextStyle(
@ -233,10 +210,18 @@ class QuillToolbarFontSizeButtonState
} }
final keyName = _getKeyName(newValue); final keyName = _getKeyName(newValue);
setState(() { setState(() {
if (keyName != 'Clear') {
_currentValue = keyName ?? _defaultDisplayText; _currentValue = keyName ?? _defaultDisplayText;
} else {
_currentValue = _defaultDisplayText;
}
if (keyName != null) { if (keyName != null) {
controller.formatSelection(Attribute.fromKeyValue( controller.formatSelection(
'size', newValue == '0' ? null : getFontSize(newValue))); Attribute.fromKeyValue(
Attribute.size.key,
newValue == '0' ? null : getFontSize(newValue),
),
);
options.onSelected?.call(newValue); options.onSelected?.call(newValue);
} }
}); });
@ -255,7 +240,7 @@ class QuillToolbarFontSizeButtonState
enabled: hasFinalWidth, enabled: hasFinalWidth,
wrapper: (child) => Expanded(child: child), wrapper: (child) => Expanded(child: child),
child: Text( child: Text(
_currentValue, widget.controller.selectedFontSize ?? _currentValue,
overflow: options.labelOverflow, overflow: options.labelOverflow,
style: options.style ?? style: options.style ??
TextStyle( TextStyle(

@ -2,6 +2,13 @@
All notable changes to this project will be documented in this file. All notable changes to this project will be documented in this file.
## 9.0.0-dev-9
* Improves the new logic of pasting HTML contents into the Editor
* Update `README.md` and the doc
* Dispose the `QuillToolbarSelectHeaderStyleButton` state listener in `dispose`
* Upgrade the font family button to material 3
* Rework the font family and font size functionallities to change the font once and type all over the editor
## 9.0.0-dev-8 ## 9.0.0-dev-8
* Better support for pasting HTML contents from external websites to the editor * Better support for pasting HTML contents from external websites to the editor
* The experimental support of converting the HTML from `quill_html_converter` is now built-in in the `flutter_quill` and removed from there (Breaking change for `quill_html_converter`) * The experimental support of converting the HTML from `quill_html_converter` is now built-in in the `flutter_quill` and removed from there (Breaking change for `quill_html_converter`)

@ -1,6 +1,6 @@
name: quill_html_converter name: quill_html_converter
description: A extension for flutter_quill package to add support for dealing with conversion to/from html description: A extension for flutter_quill package to add support for dealing with conversion to/from html
version: 9.0.0-dev-8 version: 9.0.0-dev-9
homepage: https://github.com/singerdmx/flutter-quill/tree/master/packages/quill_html_converter/ homepage: https://github.com/singerdmx/flutter-quill/tree/master/packages/quill_html_converter/
repository: https://github.com/singerdmx/flutter-quill/tree/master/packages/quill_html_converter/ repository: https://github.com/singerdmx/flutter-quill/tree/master/packages/quill_html_converter/
issue_tracker: https://github.com/singerdmx/flutter-quill/issues/ issue_tracker: https://github.com/singerdmx/flutter-quill/issues/

@ -1,6 +1,6 @@
name: flutter_quill name: flutter_quill
description: A rich text editor built for the modern Android, iOS, web and desktop platforms. It is the WYSIWYG editor and a Quill component for Flutter. description: A rich text editor built for the modern Android, iOS, web and desktop platforms. It is the WYSIWYG editor and a Quill component for Flutter.
version: 9.0.0-dev-8 version: 9.0.0-dev-9
homepage: https://1o24bbs.com/c/bulletjournal/108/ homepage: https://1o24bbs.com/c/bulletjournal/108/
repository: https://github.com/singerdmx/flutter-quill/ repository: https://github.com/singerdmx/flutter-quill/
issue_tracker: https://github.com/singerdmx/flutter-quill/issues/ issue_tracker: https://github.com/singerdmx/flutter-quill/issues/

Loading…
Cancel
Save