Option added to controller to keep inline style on new lines (#372)

Co-authored-by: Kevin Despoulains <kevin.despoulains@scriptandgo.com>
pull/382/head
kevinDespoulains 4 years ago committed by GitHub
parent a585a880cf
commit 7c7f61fe90
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({
required this.document,
required TextSelection selection,
}) : _selection = selection;
bool keepStyleOnNewLine = false,
}) : _selection = selection,
_keepStyleOnNewLine = keepStyleOnNewLine;
factory QuillController.basic() {
return QuillController(
@ -26,6 +28,10 @@ class QuillController extends ChangeNotifier {
/// Document managed by this controller.
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].
TextSelection get selection => _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 (delta == null || delta.isEmpty) {
_updateSelection(textSelection, ChangeSource.LOCAL);

Loading…
Cancel
Save