Skip to content

Commit

Permalink
Fix: Assertion Failure in line.dart When Editing Text with Block-Leve…
Browse files Browse the repository at this point in the history
…l Attributes (#2174)
  • Loading branch information
AtlasAutocode authored Sep 1, 2024
1 parent 136a23d commit cab5a9b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
14 changes: 10 additions & 4 deletions lib/src/controller/quill_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -291,27 +291,33 @@ class QuillController extends ChangeNotifier {
}

Delta? delta;
Style? style;
if (len > 0 || data is! String || data.isNotEmpty) {
delta = document.replace(index, len, data);
var shouldRetainDelta = toggledStyle.isNotEmpty &&

/// Remove block styles as they can only be attached to line endings
style = Style.attr(Map<String, Attribute>.fromEntries(toggledStyle
.attributes.entries
.where((a) => a.value.scope != AttributeScope.block)));
var shouldRetainDelta = style.isNotEmpty &&
delta.isNotEmpty &&
delta.length <= 2 &&
delta.last.isInsert;
if (shouldRetainDelta &&
toggledStyle.isNotEmpty &&
style.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);
style.values.any((attr) => !attr.isInline);
if (!anyAttributeNotInline) {
shouldRetainDelta = false;
}
}
if (shouldRetainDelta) {
final retainDelta = Delta()
..retain(index)
..retain(data is String ? data.length : 1, toggledStyle.toJson());
..retain(data is String ? data.length : 1, style.toJson());
document.compose(retainDelta, ChangeSource.local);
}
}
Expand Down
9 changes: 4 additions & 5 deletions lib/src/document/nodes/line.dart
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,10 @@ base class Line extends QuillContainer<Leaf?> {
_format(style);
} else {
// Otherwise forward to children as it's an inline format update.
assert(style.values.every((attr) =>
attr.scope == AttributeScope.inline ||
attr.scope == AttributeScope.ignore));
assert(index + local != length);
super.retain(index, local, style);
final attr = <String, Attribute>{}..addEntries(style.attributes.entries
.where((a) => a.value.scope != AttributeScope.block));
assert(index + local != length, 'Not at line end');
super.retain(index, local, Style.attr(attr));
}

final remain = len - local;
Expand Down

0 comments on commit cab5a9b

Please sign in to comment.