Fix the toggle style button

pull/1596/head
Ellet 1 year ago
parent 89d26fc47c
commit 9b4b37fe67
No known key found for this signature in database
GPG Key ID: C488CC70BBCEF0D1
  1. 14
      lib/src/widgets/quill/quill_controller.dart
  2. 14
      lib/src/widgets/raw_editor/raw_editor_state_text_input_client_mixin.dart
  3. 13
      lib/src/widgets/toolbar/buttons/toggle_style_button.dart

@ -4,6 +4,7 @@ import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
import 'package:html2md/html2md.dart' as html2md; import 'package:html2md/html2md.dart' as html2md;
import 'package:markdown/markdown.dart' as md; import 'package:markdown/markdown.dart' as md;
import 'package:meta/meta.dart';
import '../../../markdown_quill.dart'; import '../../../markdown_quill.dart';
import '../../../quill_delta.dart'; import '../../../quill_delta.dart';
@ -16,6 +17,7 @@ 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);
@ -54,6 +56,7 @@ class QuillController extends ChangeNotifier {
notifyListeners(); notifyListeners();
} }
@experimental
void setContents( void setContents(
Delta delta, { Delta delta, {
ChangeSource changeSource = ChangeSource.local, ChangeSource changeSource = ChangeSource.local,
@ -84,6 +87,17 @@ class QuillController extends ChangeNotifier {
/// The current font size, null to use the default one /// The current font size, null to use the default one
String? get selectedFontSize => _selectedFontSize; String? get selectedFontSize => _selectedFontSize;
/// 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;
}
void selectFontSize(String? newFontSize) { void selectFontSize(String? newFontSize) {
_selectedFontSize = newFontSize; _selectedFontSize = newFontSize;
} }

@ -211,9 +211,7 @@ mixin RawEditorStateTextInputClientMixin on EditorState
// TODO: There is a bug here, the first character is not being formatted // TODO: There is a bug here, the first character is not being formatted
if (widget.configurations.controller.selectedFontFamily != null) { if (widget.configurations.controller.selectedFontFamily != null) {
widget.configurations.controller.formatText( widget.configurations.controller.formatSelection(
diff.start,
diff.deleted.length,
Attribute.fromKeyValue( Attribute.fromKeyValue(
Attribute.font.key, Attribute.font.key,
widget.configurations.controller.selectedFontFamily, widget.configurations.controller.selectedFontFamily,
@ -224,9 +222,7 @@ mixin RawEditorStateTextInputClientMixin on EditorState
// TODO: A bug here too // TODO: A bug here too
if (widget.configurations.controller.selectedFontSize != null) { if (widget.configurations.controller.selectedFontSize != null) {
widget.configurations.controller.formatText( widget.configurations.controller.formatSelection(
diff.start,
diff.deleted.length,
Attribute.fromKeyValue( Attribute.fromKeyValue(
Attribute.size.key, Attribute.size.key,
widget.configurations.controller.selectedFontSize == '0' widget.configurations.controller.selectedFontSize == '0'
@ -236,6 +232,12 @@ mixin RawEditorStateTextInputClientMixin on EditorState
), ),
); );
} }
widget.configurations.controller.selectedStyles.forEach((key, value) {
if (value ?? false) {
widget.configurations.controller.formatSelection(key);
}
});
} }
} }

@ -221,9 +221,13 @@ class QuillToolbarToggleStyleButtonState
} }
void _toggleAttribute() { void _toggleAttribute() {
controller.formatSelection( controller
_isToggled! ? Attribute.clone(widget.attribute, null) : widget.attribute, ..formatSelection(
); (_isToggled ?? false)
? Attribute.clone(widget.attribute, null)
: widget.attribute,
)
..selectStyle(widget.attribute, _isToggled == true ? true : false);
} }
} }
@ -253,5 +257,6 @@ Widget defaultToggleStyleButtonBuilder(
isFilled: isEnabled ? isToggled == true : false, isFilled: isEnabled ? isToggled == true : false,
onPressed: onPressed, onPressed: onPressed,
afterPressed: afterPressed, afterPressed: afterPressed,
padding: iconTheme?.padding); padding: iconTheme?.padding,
);
} }

Loading…
Cancel
Save