-
Notifications
You must be signed in to change notification settings - Fork 249
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Quill] - Make consecutive node merges configurable (Resolves #2510) #2511
[Quill] - Make consecutive node merges configurable (Resolves #2510) #2511
Conversation
…can, for example, merge block types that can have different properties (like a BannerAttribution with Orange vs with Green).
… of just the next one. This is necessary to, e.g., compare the color of two BannerAttributions.
@angelosilvestre I'm gonna merge in to cut a release. Feel free to review after. |
|
||
var shouldMerge = false; | ||
for (final rule in blockMergeRules) { | ||
final ruleShouldMerge = rule.shouldMerge(blockTypeToMerge, node.getMetadataValue(NodeMetadata.blockType)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a small detail, we could cache node.getMetadataValue(NodeMetadata.blockType)
in a variable outside of this for loop.
abstract interface class DeltaBlockMergeRule { | ||
/// Returns `true` if two consecutive blocks with the given types should merge, | ||
/// `false` if they shouldn't, or `null` if this rule has no opinion about the merge. | ||
bool? shouldMerge(Attribution block1, Attribution block2); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using a nullable bool
looks a bit weird to me, because when reading the code that uses this, it isn't immediately obvious. I would suggest to use an enum instead.
); | ||
expect((document.getNodeAt(0)! as ParagraphNode).getMetadataValue("blockType"), blockquoteAttribution); | ||
expect((document.getNodeAt(1)! as ParagraphNode).text.toPlainText(), ""); | ||
expect(document.nodeCount, 2); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't the node count expectation be placed before the other ones? If, for some reason, there is only one node in the document the test will fail in the line above.
expect((document.getNodeAt(0)! as ParagraphNode).getMetadataValue("blockType"), blockquoteAttribution); | ||
expect((document.getNodeAt(1)! as ParagraphNode).text.toPlainText(), ""); | ||
expect((document.getNodeAt(2)! as ParagraphNode).getMetadataValue("blockType"), blockquoteAttribution); | ||
expect(document.nodeCount, 4); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here.
); | ||
expect((document.getNodeAt(0)! as ParagraphNode).getMetadataValue("blockType"), codeAttribution); | ||
expect((document.getNodeAt(1)! as ParagraphNode).text.toPlainText(), ""); | ||
expect(document.nodeCount, 2); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And here.
expect((document.getNodeAt(0)! as ParagraphNode).getMetadataValue("blockType"), codeAttribution); | ||
expect((document.getNodeAt(1)! as ParagraphNode).text.toPlainText(), ""); | ||
expect((document.getNodeAt(2)! as ParagraphNode).getMetadataValue("blockType"), codeAttribution); | ||
expect(document.nodeCount, 4); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And here.
[Quill] - Make consecutive node merges configurable (Resolves #2510)
We previously hard-coded the merging of consecutive code blocks into a single block, which seemed to be the standard Quill editor behavior. The Quill editor didn't seem to merge any other blocks.
However, an app might want to merge any number of block types, including blockquotes. An app might also want to merge custom block types, which this package can't possibly know about. Therefore, this PR makes the merge decision configurable.