Repository navigation
fix: prevent code block deletion when adding inline comments in read mode - #2146
Merged
Philipinho merged 1 commit intoMay 4, 2026
Merged
Conversation
Member
|
Thanks for contributing. |
Yundi339
pushed a commit
to Yundi339/docmost
that referenced
this pull request
Jun 18, 2026
…mode (docmost#2146) (cherry picked from commit fe18f22)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix: prevent code block deletion when adding inline comments in read mode
Summary
Fixes an issue where adding an inline comment in read mode on text inside a
codeBlockcauses the entire code block to be deleted.Root Cause
Inline comments in read mode use
yjsSelection, which is passed to the backend and applied via:setCommentMark→setYjsMark→applyMarkToYFragmentThis directly applies a mark to Yjs text nodes:
However, codeBlock nodes do not allow marks in the ProseMirror schema.
Applying marks inside them leads to an invalid document state and results in the code block being removed.
Fix
Skip applying comment marks when the selection is inside a
codeBlock.This is done by detecting the parent node (nodeName) in applyMarkToYFragment and avoiding item.format(...) when inside a codeBlock.
Result
✅ Code block no longer gets deleted in read mode
⚠️ Inline highlighting inside code blocks is not supported (consistent with existing edit-mode behavior)
✅ Paragraph inline comments continue to work (highlight + scroll)
After Change -
AfterChange.mp4
Alternative considered (frontend-only fix)
I also tested skipping yjsSelection in the frontend:
This approach was not chosen because:
Handling it in the backend ensures:
Notes
This PR focuses on preventing document corruption.
Inline highlighting inside code blocks is currently not supported (also not working in edit mode). Supporting it would require changes to the schema or decoration.
Happy to explore that separately if needed.
Fixes #2122