From daa774b0f042fc67f553812e1d65bd385d2918e3 Mon Sep 17 00:00:00 2001 From: Xin Yao Date: Wed, 10 Mar 2021 21:33:06 -0800 Subject: [PATCH] Bug fix: Can not insert newline when Bold is toggled ON --- lib/widgets/controller.dart | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/widgets/controller.dart b/lib/widgets/controller.dart index 2661b745..534184c9 100644 --- a/lib/widgets/controller.dart +++ b/lib/widgets/controller.dart @@ -86,11 +86,19 @@ class QuillController extends ChangeNotifier { print('document.replace failed: $e'); throw e; } - final shouldRetainDelta = delta != null && + bool shouldRetainDelta = delta != null && toggledStyle.isNotEmpty && delta.isNotEmpty && delta.length <= 2 && delta.last.isInsert; + if (shouldRetainDelta && toggledStyle.isNotEmpty) { + // if all attributes are inline, shouldRetainDelta should be false + final anyAttributeNotInline = + toggledStyle.values.any((attr) => !attr.isInline); + if (!anyAttributeNotInline) { + shouldRetainDelta = false; + } + } if (shouldRetainDelta) { Delta retainDelta = Delta() ..retain(index)