From 25980df3fbc016666903371496ffca0e415071ca Mon Sep 17 00:00:00 2001 From: X Code Date: Sat, 18 Dec 2021 18:23:34 -0800 Subject: [PATCH] PreserveBlockStyleOnInsertRule supports checked list --- lib/src/models/rules/insert.dart | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/src/models/rules/insert.dart b/lib/src/models/rules/insert.dart index 67522d38..7408b20c 100644 --- a/lib/src/models/rules/insert.dart +++ b/lib/src/models/rules/insert.dart @@ -87,12 +87,17 @@ class PreserveBlockStyleOnInsertRule extends InsertRule { return null; } - Map? resetStyle; + final resetStyle = {}; // If current line had heading style applied to it we'll need to move this // style to the newly inserted line before it and reset style of the // original line. if (lineStyle.containsKey(Attribute.header.key)) { - resetStyle = Attribute.header.toJson(); + resetStyle.addAll(Attribute.header.toJson()); + } + + // Similarly for the checked style + if (lineStyle.attributes[Attribute.list.key] == Attribute.checked) { + resetStyle.addAll(Attribute.checked.toJson()); } // Go over each inserted line and ensure block style is applied. @@ -113,7 +118,7 @@ class PreserveBlockStyleOnInsertRule extends InsertRule { } // Reset style of the original newline character if needed. - if (resetStyle != null) { + if (resetStyle.isNotEmpty) { delta ..retain(nextNewLine.item2!) ..retain((nextNewLine.item1!.data as String).indexOf('\n'))