Merge branch 'singerdmx:master' into master

pull/382/head
Aldy J 4 years ago committed by GitHub
commit 6ce2c44d03
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 17
      lib/src/widgets/controller.dart

@ -14,7 +14,9 @@ class QuillController extends ChangeNotifier {
QuillController({ QuillController({
required this.document, required this.document,
required TextSelection selection, required TextSelection selection,
}) : _selection = selection; bool keepStyleOnNewLine = false,
}) : _selection = selection,
_keepStyleOnNewLine = keepStyleOnNewLine;
factory QuillController.basic() { factory QuillController.basic() {
return QuillController( return QuillController(
@ -26,6 +28,10 @@ class QuillController extends ChangeNotifier {
/// Document managed by this controller. /// Document managed by this controller.
final Document document; final Document document;
/// Tells whether to keep or reset the [toggledStyle]
/// when user adds a new line.
final bool _keepStyleOnNewLine;
/// Currently selected text within the [document]. /// Currently selected text within the [document].
TextSelection get selection => _selection; TextSelection get selection => _selection;
TextSelection _selection; TextSelection _selection;
@ -135,7 +141,14 @@ class QuillController extends ChangeNotifier {
} }
} }
toggledStyle = Style(); if (_keepStyleOnNewLine) {
final style = getSelectionStyle();
final notInlineStyle = style.attributes.values.where((s) => !s.isInline);
toggledStyle = style.removeAll(notInlineStyle.toSet());
} else {
toggledStyle = Style();
}
if (textSelection != null) { if (textSelection != null) {
if (delta == null || delta.isEmpty) { if (delta == null || delta.isEmpty) {
_updateSelection(textSelection, ChangeSource.LOCAL); _updateSelection(textSelection, ChangeSource.LOCAL);

Loading…
Cancel
Save