fix: Inline code clears comments (BLO-1207)#2832
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
📝 WalkthroughWalkthroughCode marks now allow comment marks to overlap by removing the comment mark from the exclusion list when the mark is created. A lifecycle hook filters the exclusion list conditionally, and an end-to-end test validates that comments and inline code coexist on the same text selection. ChangesCode and Comment Mark Overlap
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
@blocknote/ariakit
@blocknote/code-block
@blocknote/core
@blocknote/mantine
@blocknote/react
@blocknote/server-util
@blocknote/shadcn
@blocknote/xl-ai
@blocknote/xl-docx-exporter
@blocknote/xl-email-exporter
@blocknote/xl-multi-column
@blocknote/xl-odt-exporter
@blocknote/xl-pdf-exporter
commit: |
|
| onBeforeCreate() { | ||
| // By default, code marks are configured to not overlap with any other | ||
| // marks with `exclude: "_"`. However, comment marks should still be | ||
| // allowed to overlap code marks. There is unfortunately no way to make | ||
| // the `exclude` option contain all possible marks except comments, so | ||
| // we instead remove the comment mark from it in `onBeforeCreate`. | ||
| const commentType = this.editor.schema.marks.comment; | ||
| const codeType = this.type as MarkType & { | ||
| excluded?: readonly MarkType[]; | ||
| }; | ||
|
|
||
| if (commentType && codeType.excluded?.includes(commentType)) { | ||
| codeType.excluded = codeType.excluded.filter( | ||
| (markType) => markType !== commentType, | ||
| ); | ||
| } | ||
| }, |
There was a problem hiding this comment.
I don't love this solution, can the excluded be a function in tiptap? And we can read the editor to see the other marks that exist in the schema. It being a runtime hack isn't great, especially when we can know all of the marks that the editor has included in it
Summary
This PR fixes an issues where comments cannot overlap inline code. This is because the inline code mark has
exclude: "_"in its spec, meaning no other marks can overlap it. This makes sense for things like colors and bold/italic/etc, but not comments. Therefore, an exception has been added.Closes #2803
Rationale
This is a bug.
Changes
Codemark withonBeforeCreateto remove the comment mark from theexcludearray.Impact
N/A
Testing
Added e2e test.
Screenshots/Video
N/A
Checklist
Additional Notes
N/A
Summary by CodeRabbit