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/offset_value.dart';
import '../../utils/delta.dart';
import '../toolbar/buttons/toggle_style_button.dart';
typedef ReplaceTextCallback = bool Function(int index, int len, Object? data);
typedef DeleteCallback = void Function(int cursorPosition, bool forward);
@ -67,40 +66,6 @@ class QuillController extends ChangeNotifier {
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]
/// when user adds a new line.
final bool keepStyleOnNewLine;

@ -67,12 +67,10 @@ class QuillToolbarFontFamilyButtonState
@override
void didUpdateWidget(covariant QuillToolbarFontFamilyButton oldWidget) {
super.didUpdateWidget(oldWidget);
if (oldWidget.controller == controller) {
return;
if (oldWidget.controller != controller) {
oldWidget.controller.removeListener(_didChangeEditingValue);
controller.addListener(_didChangeEditingValue);
}
controller
..removeListener(_didChangeEditingValue)
..addListener(_didChangeEditingValue);
}
@override
@ -218,12 +216,6 @@ class QuillToolbarFontFamilyButtonState
options.onSelected?.call(newValue);
}
});
if (fontFamily.value == 'Clear') {
controller.selectFontFamily(null);
return;
}
controller.selectFontFamily(fontFamily);
},
child: Text(
fontFamily.key.toString(),

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

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

Loading…
Cancel
Save