PreserveBlockStyleOnInsertRule supports checked list

pull/541/head
X Code 3 years ago
parent 1aeb7028ae
commit 25980df3fb
  1. 11
      lib/src/models/rules/insert.dart

@ -87,12 +87,17 @@ class PreserveBlockStyleOnInsertRule extends InsertRule {
return null; return null;
} }
Map<String, dynamic>? resetStyle; final resetStyle = <String, dynamic>{};
// If current line had heading style applied to it we'll need to move this // 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 // style to the newly inserted line before it and reset style of the
// original line. // original line.
if (lineStyle.containsKey(Attribute.header.key)) { 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. // 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. // Reset style of the original newline character if needed.
if (resetStyle != null) { if (resetStyle.isNotEmpty) {
delta delta
..retain(nextNewLine.item2!) ..retain(nextNewLine.item2!)
..retain((nextNewLine.item1!.data as String).indexOf('\n')) ..retain((nextNewLine.item1!.data as String).indexOf('\n'))

Loading…
Cancel
Save