Fixed style recognition when caret is at the beginning/end of style

pull/1416/head
Alspb 2 years ago
parent 848a0b5d02
commit 15e6bfd018
  1. 35
      lib/src/models/documents/document.dart

@ -156,19 +156,28 @@ class Document {
/// included in the result.
Style collectStyle(int index, int len) {
final res = queryChild(index);
// -1 because the cursor is at the part of the line that is not visible
// Bug: When the caret is in the middle of the paragraph
// and at the end of the format string, it will display the wrong state
// of the format button
final isLinkStyle =
res.node?.style.attributes[Attribute.link.key]?.value == true;
// In this case, we have an exception, this is a link.
// When node is a link we will not -1
return (res.node as Line).collectStyle(
len == 0 && res.node != null && !isLinkStyle
? res.offset - 1
: res.offset,
len);
Style rangeStyle;
if (len > 0) {
return (res.node as Line).collectStyle(res.offset, len);
}
if (res.offset == 0) {
rangeStyle = (res.node as Line).collectStyle(res.offset, len);
return rangeStyle.removeAll({
for (final attr in rangeStyle.values)
if (attr.isInline) attr
});
}
rangeStyle = (res.node as Line).collectStyle(res.offset - 1, len);
final linkAttribute = rangeStyle.attributes[Attribute.link.key];
if ((linkAttribute != null) &&
(linkAttribute.value !=
(res.node as Line)
.collectStyle(res.offset, len)
.attributes[Attribute.link.key]
?.value)) {
return rangeStyle.removeAll({linkAttribute});
}
return rangeStyle;
}
/// Returns all styles and Embed for each node within selection

Loading…
Cancel
Save