From 14662c229d0d7bf39d0b3333419fb12b0e152bf8 Mon Sep 17 00:00:00 2001 From: Xin Yao Date: Wed, 10 Mar 2021 23:36:14 -0800 Subject: [PATCH] Bug fix: Can not insert newline when Bold is toggled ON (#75) * Bug fix: Can not insert newline when Bold is toggled ON * Fix --- lib/widgets/controller.dart | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/widgets/controller.dart b/lib/widgets/controller.dart index 2661b745..9c23d327 100644 --- a/lib/widgets/controller.dart +++ b/lib/widgets/controller.dart @@ -86,11 +86,22 @@ 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 && + delta.length == 2 && + delta.last.data == '\n') { + // 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)