Option added to controller to keep inline style on new lines

pull/372/head
Kevin Despoulains 4 years ago
parent 36fb2e1ca8
commit f13e0ebe26
  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