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

Loading…
Cancel
Save