Skip to content
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

Merged

Conversation

matthew-carroll
Copy link
Contributor

[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.

…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.
@matthew-carroll
Copy link
Contributor Author

@angelosilvestre I'm gonna merge in to cut a release. Feel free to review after.

@matthew-carroll matthew-carroll merged commit c79892d into main Jan 16, 2025
16 checks passed
@matthew-carroll matthew-carroll deleted the 2510_quill-configurable-block-merging-when-parsed branch January 16, 2025 06:50

var shouldMerge = false;
for (final rule in blockMergeRules) {
final ruleShouldMerge = rule.shouldMerge(blockTypeToMerge, node.getMetadataValue(NodeMetadata.blockType));
Copy link
Collaborator

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);
Copy link
Collaborator

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);
Copy link
Collaborator

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);
Copy link
Collaborator

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);
Copy link
Collaborator

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);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Quill] - Make consecutive block merges configurable
2 participants