Fix conflict with the exsisting solution

pull/1596/head
Ellet 1 year ago
parent 83020a17fb
commit e993e668e5
No known key found for this signature in database
GPG Key ID: C488CC70BBCEF0D1
  1. 44
      lib/src/widgets/quill/quill_controller.dart
  2. 19
      lib/src/widgets/raw_editor/raw_editor_state_text_input_client_mixin.dart

@ -1,6 +1,6 @@
import 'dart:math' as math; import 'dart:math' as math;
import 'package:flutter/services.dart'; import 'package:flutter/services.dart' show ClipboardData, Clipboard;
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;
@ -26,14 +26,13 @@ class QuillController extends ChangeNotifier {
QuillController({ QuillController({
required Document document, required Document document,
required TextSelection selection, required TextSelection selection,
bool keepStyleOnNewLine = false, this.keepStyleOnNewLine = true,
this.onReplaceText, this.onReplaceText,
this.onDelete, this.onDelete,
this.onSelectionCompleted, this.onSelectionCompleted,
this.onSelectionChanged, this.onSelectionChanged,
}) : _document = document, }) : _document = document,
_selection = selection, _selection = selection;
_keepStyleOnNewLine = keepStyleOnNewLine;
factory QuillController.basic() { factory QuillController.basic() {
return QuillController( return QuillController(
@ -71,6 +70,9 @@ 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 /// The current font family, null to use the default one
String? _selectedFontFamily; String? _selectedFontFamily;
@ -87,6 +89,10 @@ 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;
void selectFontSize(String? newFontSize) {
_selectedFontSize = newFontSize;
}
/// For the [QuillToolbarToggleStyleButton] /// For the [QuillToolbarToggleStyleButton]
final Map<Attribute, bool?> _selectedStyles = {}; final Map<Attribute, bool?> _selectedStyles = {};
@ -98,13 +104,9 @@ class QuillController extends ChangeNotifier {
_selectedStyles[attribute] = value; _selectedStyles[attribute] = value;
} }
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;
/// Currently selected text within the [document]. /// Currently selected text within the [document].
TextSelection get selection => _selection; TextSelection get selection => _selection;
@ -283,6 +285,7 @@ class QuillController extends ChangeNotifier {
Object? data, Object? data,
TextSelection? textSelection, { TextSelection? textSelection, {
bool ignoreFocus = false, bool ignoreFocus = false,
bool shouldNotifyListeners = true,
}) { }) {
assert(data is String || data is Embeddable); assert(data is String || data is Embeddable);
@ -338,7 +341,9 @@ class QuillController extends ChangeNotifier {
if (ignoreFocus) { if (ignoreFocus) {
ignoreFocusOnTextChange = true; ignoreFocusOnTextChange = true;
} }
if (shouldNotifyListeners) {
notifyListeners(); notifyListeners();
}
ignoreFocusOnTextChange = false; ignoreFocusOnTextChange = false;
} }
@ -356,7 +361,12 @@ class QuillController extends ChangeNotifier {
}); });
} }
void formatText(int index, int len, Attribute? attribute) { void formatText(
int index,
int len,
Attribute? attribute, {
bool shouldNotifyListeners = true,
}) {
if (len == 0 && if (len == 0 &&
attribute!.isInline && attribute!.isInline &&
attribute.key != Attribute.link.key) { attribute.key != Attribute.link.key) {
@ -375,11 +385,19 @@ class QuillController extends ChangeNotifier {
if (selection != adjustedSelection) { if (selection != adjustedSelection) {
_updateSelection(adjustedSelection, ChangeSource.local); _updateSelection(adjustedSelection, ChangeSource.local);
} }
if (shouldNotifyListeners) {
notifyListeners(); notifyListeners();
} }
}
void formatSelection(Attribute? attribute) { void formatSelection(Attribute? attribute,
formatText(selection.start, selection.end - selection.start, attribute); {bool shouldNotifyListeners = true}) {
formatText(
selection.start,
selection.end - selection.start,
attribute,
shouldNotifyListeners: shouldNotifyListeners,
);
} }
void moveCursorToStart() { void moveCursorToStart() {
@ -461,7 +479,7 @@ class QuillController extends ChangeNotifier {
_selection = selection.copyWith( _selection = selection.copyWith(
baseOffset: math.min(selection.baseOffset, end), baseOffset: math.min(selection.baseOffset, end),
extentOffset: math.min(selection.extentOffset, end)); extentOffset: math.min(selection.extentOffset, end));
if (_keepStyleOnNewLine) { if (keepStyleOnNewLine) {
final style = getSelectionStyle(); final style = getSelectionStyle();
final ignoredStyles = style.attributes.values.where( final ignoredStyles = style.attributes.values.where(
(s) => !s.isInline || s.key == Attribute.link.key, (s) => !s.isInline || s.key == Attribute.link.key,

@ -208,8 +208,6 @@ mixin RawEditorStateTextInputClientMixin on EditorState
value.selection, value.selection,
); );
// 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.formatSelection( widget.configurations.controller.formatSelection(
Attribute.fromKeyValue( Attribute.fromKeyValue(
@ -219,8 +217,6 @@ mixin RawEditorStateTextInputClientMixin on EditorState
); );
} }
// TODO: The same bug here
if (widget.configurations.controller.selectedFontSize != null) { if (widget.configurations.controller.selectedFontSize != null) {
widget.configurations.controller.formatSelection( widget.configurations.controller.formatSelection(
Attribute.fromKeyValue( Attribute.fromKeyValue(
@ -232,14 +228,13 @@ mixin RawEditorStateTextInputClientMixin on EditorState
), ),
); );
} }
// if (widget.configurations.controller.keepStyleOnNewLine) {
// TODO: The same bug here // widget.configurations.controller.selectedStyles.forEach((key, value) {
// if (value ?? false) {
widget.configurations.controller.selectedStyles.forEach((key, value) { // widget.configurations.controller.formatSelection(key);
if (value ?? false) { // }
widget.configurations.controller.formatSelection(key); // });
} // }
});
} }
} }

Loading…
Cancel
Save