Fix FontFamily and Size button actions

pull/1829/head
AtlasAutocode 1 year ago
parent 472b89c956
commit dd03bffa0f
  1. 35
      lib/src/widgets/quill/quill_controller.dart
  2. 14
      lib/src/widgets/toolbar/buttons/font_family_button.dart
  3. 14
      lib/src/widgets/toolbar/buttons/font_size_button.dart
  4. 5
      lib/src/widgets/toolbar/buttons/toggle_style_button.dart

@ -14,7 +14,6 @@ import '../../models/structs/doc_change.dart';
import '../../models/structs/image_url.dart'; import '../../models/structs/image_url.dart';
import '../../models/structs/offset_value.dart'; import '../../models/structs/offset_value.dart';
import '../../utils/delta.dart'; import '../../utils/delta.dart';
import '../toolbar/buttons/toggle_style_button.dart';
typedef ReplaceTextCallback = bool Function(int index, int len, Object? data); typedef ReplaceTextCallback = bool Function(int index, int len, Object? data);
typedef DeleteCallback = void Function(int cursorPosition, bool forward); typedef DeleteCallback = void Function(int cursorPosition, bool forward);
@ -67,40 +66,6 @@ class QuillController extends ChangeNotifier {
notifyListeners(); notifyListeners();
} }
// Thoses are the values that the user selects and not the one
// from the current line
/// The current font family, null to use the default one
MapEntry<String, String>? _selectedFontFamily;
/// The current font family, null to use the default one
MapEntry<String, String>? get selectedFontFamily => _selectedFontFamily;
void selectFontFamily(MapEntry<String, String>? newFontFamily) {
_selectedFontFamily = newFontFamily;
}
/// The current font size, null to use the default one
MapEntry<String, String>? _selectedFontSize;
/// The current font size, null to use the default one
MapEntry<String, String>? get selectedFontSize => _selectedFontSize;
void selectFontSize(MapEntry<String, String>? newFontSize) {
_selectedFontSize = newFontSize;
}
/// For the [QuillToolbarToggleStyleButton]
final Map<Attribute, bool?> _selectedStyles = {};
/// For the [QuillToolbarToggleStyleButton]
Map<Attribute, bool?> get selectedStyles => _selectedStyles;
/// For the [QuillToolbarToggleStyleButton]
void selectStyle(Attribute attribute, bool value) {
_selectedStyles[attribute] = value;
}
/// 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;

@ -67,12 +67,10 @@ class QuillToolbarFontFamilyButtonState
@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; oldWidget.controller.removeListener(_didChangeEditingValue);
controller.addListener(_didChangeEditingValue);
} }
controller
..removeListener(_didChangeEditingValue)
..addListener(_didChangeEditingValue);
} }
@override @override
@ -218,12 +216,6 @@ class QuillToolbarFontFamilyButtonState
options.onSelected?.call(newValue); options.onSelected?.call(newValue);
} }
}); });
if (fontFamily.value == 'Clear') {
controller.selectFontFamily(null);
return;
}
controller.selectFontFamily(fontFamily);
}, },
child: Text( child: Text(
fontFamily.key.toString(), fontFamily.key.toString(),

@ -91,12 +91,10 @@ class QuillToolbarFontSizeButtonState
@override @override
void didUpdateWidget(covariant QuillToolbarFontSizeButton oldWidget) { void didUpdateWidget(covariant QuillToolbarFontSizeButton oldWidget) {
super.didUpdateWidget(oldWidget); super.didUpdateWidget(oldWidget);
if (oldWidget.controller == controller) { if (oldWidget.controller != controller) {
return; oldWidget.controller.removeListener(_didChangeEditingValue);
controller.addListener(_didChangeEditingValue);
} }
controller
..removeListener(_didChangeEditingValue)
..addListener(_didChangeEditingValue);
} }
@override @override
@ -208,12 +206,6 @@ class QuillToolbarFontSizeButtonState
options.onSelected?.call(newValue); options.onSelected?.call(newValue);
} }
}); });
if (fontSize.value == '0') {
controller.selectFontSize(null);
return;
}
controller.selectFontSize(fontSize);
}, },
child: Text( child: Text(
fontSize.key.toString(), fontSize.key.toString(),

@ -218,12 +218,11 @@ class QuillToolbarToggleStyleButtonState
void _toggleAttribute() { void _toggleAttribute() {
controller controller
..formatSelection( .formatSelection(
(_isToggled ?? false) (_isToggled ?? false)
? Attribute.clone(widget.attribute, null) ? Attribute.clone(widget.attribute, null)
: widget.attribute, : widget.attribute,
) );
..selectStyle(widget.attribute, _isToggled ?? false);
} }
} }

Loading…
Cancel
Save