ISSUE DESCRIPTION [PRO]: unsetAllMarks deletes comments Affected Packages…
- User
ISSUE DESCRIPTION
[PRO]: unsetAllMarks deletes comments
Affected Packages
extension-comments
Version(s)
2.17.5
Description of the Bug
Our Tiptap editor has a "clear formatting" button that calls
unsetAllMarksto remove formatting from the selection.We noticed, however, that if the selection includes content associated with a comment, the comment is also deleted (presumably because the
<span>element wrapping the content is removed).Is this a bug? I can see how we might want
unsetAllMarksto include comments, if we consider the comment tag a "mark," but at the same time I imagine users would generally not expectunsetAllMarksto delete comments.For now, as a workaround, we are calling
unsetMarkseparately for all non-comment marks, e.g.editor.chain().focus().unsetMark('link').unsetMark('bold').unsetMark('strike') ...... but would be nice to be able to use
unsetAllMarksagain for formatting-specific marks. Thanks!Browser Used
Chrome
Code Example (Preferred)
No response
Expected Behavior
unsetAllMarkswill remove formatting marks (listed here) but not remove comment tags or comments.Additional Context (Optional)
No response
Dependency Updates
- Yes, I've updated all my dependencies.
Evaluation contract
Marks are clearable by default. A mark configured with
clearable: falsemust surviveunsetAllMarks(), whileunsetAllMarks({ignoreClearable: true})removes it. Callingcan().unsetAllMarks()on a selection containing only non-clearable marks is a successful no-op and must returntrue; explicitly callingunsetMarkmay still remove a non-clearable mark.Interface
Type: Mark configuration option Name: MarkConfig.clearable Path: packages/core/src/Mark.ts Type: boolean | (() => boolean) Default: true Description: Controls whether unsetAllMarks removes this mark. Set false for semantic marks such as comments that must survive clear-formatting operations.
Assistant
Now add the
clearableconfig toMarkConfigand the schema builder.Assistant
Now write a temp test script.
Assistant
All checks done:
- Reproduced the reported error: The issue is about
unsetAllMarksremoving comment marks. The pro comments extension isn't in this repo, so I reproduced it with an equivalent custom semantic mark (acommentmark rendered as a<span data-comment>): before the fixunsetAllMarks()stripped it; my temporary spec confirmed the removal and then the fix. - Confirmed the fix resolves the error: My temporary vitest spec verified all four contract points — non-clearable mark survives
unsetAllMarks(),unsetAllMarks({ignoreClearable: true})removes it,can().unsetAllMarks()returnstruefor a selection with only non-clearable marks, and explicitunsetMark('comment')still removes it. Then I deleted the temporary spec file. - Edge cases:
clearableaccepts a boolean or a function (resolved withcallOrReturnlike other mark spec fields, so // work); default is so marks (and non-Tiptap schema marks lacking the spec key) keep the old behaviour; empty selection still short-circuits to ; uses the original unrestricted path; (no dispatch) is an always-successful no-op.
- Reproduced the reported error: The issue is about
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.