Improve font family button

pull/1578/head
Ellet 1 year ago
parent 615a0a21f9
commit 2283d8b3ce
No known key found for this signature in database
GPG Key ID: C488CC70BBCEF0D1
  1. 3
      CHANGELOG.md
  2. 1
      example/devtools_options.yaml
  3. 2
      lib/src/widgets/quill/quill_controller.dart
  4. 1
      lib/src/widgets/raw_editor/raw_editor_state.dart
  5. 18
      lib/src/widgets/raw_editor/raw_editor_state_text_input_client_mixin.dart
  6. 59
      lib/src/widgets/toolbar/buttons/font_family_button.dart
  7. 18
      lib/src/widgets/toolbar/buttons/select_header_style_button.dart

@ -5,6 +5,9 @@ All notable changes to this project will be documented in this file.
## 9.0.0-dev-9 ## 9.0.0-dev-9
* Improves the new logic of pasting HTML contents into the Editor * Improves the new logic of pasting HTML contents into the Editor
* Update `README.md` and the doc * 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 functionallity 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

@ -64,7 +64,7 @@ class QuillController extends ChangeNotifier {
String? get selectedFontFamily => _selectedFontFamily; String? get selectedFontFamily => _selectedFontFamily;
void selectFontFamily(String newFontFamily) { void selectFontFamily(String newFontFamily) {
_selectedFontFamily = selectedFontFamily; _selectedFontFamily = newFontFamily;
} }
/// Tells whether to keep or reset the [toggledStyle] /// Tells whether to keep or reset the [toggledStyle]

@ -28,7 +28,6 @@ import '../../models/documents/nodes/embeddable.dart';
import '../../models/documents/nodes/leaf.dart' as leaf; import '../../models/documents/nodes/leaf.dart' as leaf;
import '../../models/documents/nodes/line.dart'; import '../../models/documents/nodes/line.dart';
import '../../models/documents/nodes/node.dart'; import '../../models/documents/nodes/node.dart';
import '../../models/quill_delta.dart';
import '../../models/structs/offset_value.dart'; import '../../models/structs/offset_value.dart';
import '../../models/structs/vertical_spacing.dart'; import '../../models/structs/vertical_spacing.dart';
import '../../utils/cast.dart'; import '../../utils/cast.dart';

@ -7,6 +7,7 @@ import 'package:flutter/material.dart' show Theme;
import 'package:flutter/scheduler.dart' show SchedulerBinding; import 'package:flutter/scheduler.dart' show SchedulerBinding;
import 'package:flutter/services.dart'; import 'package:flutter/services.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 '../editor/editor.dart'; import '../editor/editor.dart';
@ -200,7 +201,22 @@ mixin RawEditorStateTextInputClientMixin on EditorState
.updateSelection(value.selection, ChangeSource.local); .updateSelection(value.selection, ChangeSource.local);
} else { } else {
widget.configurations.controller.replaceText( widget.configurations.controller.replaceText(
diff.start, diff.deleted.length, diff.inserted, value.selection); diff.start,
diff.deleted.length,
diff.inserted,
value.selection,
);
print(widget.configurations.controller.selectedFontFamily != null);
if (widget.configurations.controller.selectedFontFamily != null) {
widget.configurations.controller.formatText(
diff.start,
diff.deleted.length,
Attribute.fromKeyValue(
Attribute.font.key,
widget.configurations.controller.selectedFontFamily,
),
);
}
} }
} }

@ -51,39 +51,39 @@ class QuillToolbarFontFamilyButtonState
void _initState() { void _initState() {
_currentValue = _defaultDisplayText; _currentValue = _defaultDisplayText;
controller.addListener(_didChangeEditingValue); // controller.addListener(_didChangeEditingValue);
} }
@override // @override
void dispose() { // void dispose() {
controller.removeListener(_didChangeEditingValue); // controller.removeListener(_didChangeEditingValue);
super.dispose(); // super.dispose();
} // }
String get _defaultDisplayText { String get _defaultDisplayText {
return options.initialValue ?? widget.defaultDispalyText; return options.initialValue ?? widget.defaultDispalyText;
} }
@override // @override
void didUpdateWidget(covariant QuillToolbarFontFamilyButton oldWidget) { // void didUpdateWidget(covariant QuillToolbarFontFamilyButton oldWidget) {
super.didUpdateWidget(oldWidget); // super.didUpdateWidget(oldWidget);
if (oldWidget.controller == controller) { // if (oldWidget.controller == controller) {
return; // return;
} // }
controller // controller
..removeListener(_didChangeEditingValue) // ..removeListener(_didChangeEditingValue)
..addListener(_didChangeEditingValue); // ..addListener(_didChangeEditingValue);
} // }
void _didChangeEditingValue() { // void _didChangeEditingValue() {
final attribute = _selectionStyle.attributes[options.attribute.key]; // final attribute = _selectionStyle.attributes[options.attribute.key];
if (attribute == null) { // if (attribute == null) {
setState(() => _currentValue = _defaultDisplayText); // setState(() => _currentValue = _defaultDisplayText);
return; // return;
} // }
final keyName = _getKeyName(attribute.value); // final keyName = _getKeyName(attribute.value);
setState(() => _currentValue = keyName ?? _defaultDisplayText); // setState(() => _currentValue = keyName ?? _defaultDisplayText);
} // }
Map<String, String> get rawItemsMap { Map<String, String> get rawItemsMap {
final rawItemsMap = final rawItemsMap =
@ -225,6 +225,9 @@ class QuillToolbarFontFamilyButtonState
height: options.itemHeight ?? kMinInteractiveDimension, height: options.itemHeight ?? kMinInteractiveDimension,
padding: options.itemPadding, padding: options.itemPadding,
onTap: () { onTap: () {
if (fontFamily.value == 'Clear') {
return;
}
controller.selectFontFamily(fontFamily.value); controller.selectFontFamily(fontFamily.value);
}, },
child: Text( child: Text(
@ -251,11 +254,13 @@ class QuillToolbarFontFamilyButtonState
} }
final keyName = _getKeyName(newValue); final keyName = _getKeyName(newValue);
setState(() { setState(() {
if (keyName != 'Clear') {
_currentValue = keyName ?? _defaultDisplayText; _currentValue = keyName ?? _defaultDisplayText;
}
if (keyName != null) { if (keyName != null) {
controller.formatSelection( controller.formatSelection(
Attribute.fromKeyValue( Attribute.fromKeyValue(
'font', Attribute.font.key,
newValue == 'Clear' ? null : newValue, newValue == 'Clear' ? null : newValue,
), ),
); );
@ -277,7 +282,7 @@ class QuillToolbarFontFamilyButtonState
enabled: hasFinalWidth, enabled: hasFinalWidth,
wrapper: (child) => Expanded(child: child), wrapper: (child) => Expanded(child: child),
child: Text( child: Text(
_currentValue, widget.controller.selectedFontFamily ?? _currentValue,
maxLines: 1, maxLines: 1,
overflow: options.labelOverflow, overflow: options.labelOverflow,
style: options.style ?? style: options.style ??

@ -37,6 +37,24 @@ class _QuillToolbarSelectHeaderStyleButtonState
widget.controller.addListener(_didChangeEditingValue); widget.controller.addListener(_didChangeEditingValue);
} }
@override
void dispose() {
widget.controller.removeListener(_didChangeEditingValue);
super.dispose();
}
@override
void didUpdateWidget(
covariant QuillToolbarSelectHeaderStyleButton oldWidget) {
super.didUpdateWidget(oldWidget);
if (oldWidget.controller == widget.controller) {
return;
}
widget.controller
..removeListener(_didChangeEditingValue)
..addListener(_didChangeEditingValue);
}
void _didChangeEditingValue() { void _didChangeEditingValue() {
final newSelectedItem = _getOptionsItemByAttribute(_getHeaderValue()); final newSelectedItem = _getOptionsItemByAttribute(_getHeaderValue());
if (newSelectedItem == _selectedItem) { if (newSelectedItem == _selectedItem) {

Loading…
Cancel
Save