collectAllStyles should return List<Style>

pull/295/head
Xin Yao 4 years ago
parent bbabf4e25d
commit dad5c676cb
  1. 2
      lib/src/models/documents/document.dart
  2. 14
      lib/src/models/documents/nodes/line.dart
  3. 9
      lib/src/widgets/controller.dart
  4. 9
      lib/src/widgets/toolbar/clear_format_button.dart

@ -127,7 +127,7 @@ class Document {
}
/// Returns all style for any character within the specified text range.
Style collectAllStyles(int index, int len) {
List<Style> collectAllStyles(int index, int len) {
final res = queryChild(index);
return (res.node as Line).collectAllStyles(res.offset, len);
}

@ -370,32 +370,32 @@ class Line extends Container<Leaf?> {
}
/// Returns all style for any character within the specified text range.
Style collectAllStyles(int offset, int len) {
List<Style> collectAllStyles(int offset, int len) {
final local = math.min(length - offset, len);
var result = Style();
final result = <Style>[];
final data = queryChild(offset, true);
var node = data.node as Leaf?;
if (node != null) {
result = result.mergeAll(node.style);
result.add(node.style);
var pos = node.length - data.offset;
while (!node!.isLast && pos < local) {
node = node.next as Leaf?;
result = result.mergeAll(node!.style);
result.add(node!.style);
pos += node.length;
}
}
result = result.mergeAll(style);
result.add(style);
if (parent is Block) {
final block = parent as Block;
result = result.mergeAll(block.style);
result.add(block.style);
}
final remaining = len - local;
if (remaining > 0) {
final rest = nextLine!.collectAllStyles(0, remaining);
result = result.mergeAll(rest);
result.addAll(rest);
}
return result;

@ -64,10 +64,11 @@ class QuillController extends ChangeNotifier {
}
/// Returns all style for any character within the specified text range.
Style getAllSelectionStyles() {
return document
.collectAllStyles(selection.start, selection.end - selection.start)
.mergeAll(toggledStyle);
List<Style> getAllSelectionStyles() {
final styles = document.collectAllStyles(
selection.start, selection.end - selection.start)
..add(toggledStyle);
return styles;
}
void undo() {

@ -33,8 +33,13 @@ class _ClearFormatButtonState extends State<ClearFormatButton> {
icon: Icon(widget.icon, size: widget.iconSize, color: iconColor),
fillColor: fillColor,
onPressed: () {
for (final k
in widget.controller.getAllSelectionStyles().attributes.values) {
final keys = <Attribute>{};
for (final style in widget.controller.getAllSelectionStyles()) {
for (final k in style.attributes.values) {
keys.add(k);
}
}
for (final k in keys) {
widget.controller.formatSelection(Attribute.clone(k, null));
}
});

Loading…
Cancel
Save