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
Let me explore the repository structure to understand the codebase.
Assistant
I need to make one tool call at a time.
Assistant
Now let me look at the Extendable.ts to understand how config is processed, and find the comments extension.
Assistant
Now let me find the comments extension to understand how it's configured.
Assistant
There's no comments extension in the repo. The issue mentions
extension-commentsas an affected package, but it's not present. Let me check the starter-kit and the existing tests for unsetAllMarks.Assistant
Let me look at how other commands access extensions and mark types. Let me check the command types and how editor schema is accessed.
Assistant
Now let me look at how a command accesses extensions to get mark configs. Let me look at an example command that uses extensions, like toggleMark or resetAttributes.
Assistant
Let me find a command that accesses
editordirectly to get extensions. Let me search foreditor.extensionManagerorextensionManagerusage in commands.Assistant
Now I understand the pattern. Let me look at how the command manager passes props to commands to see what's available (editor, state, tr, etc).
Assistant
So
editoris available in command props. Now I have a good understanding. Let me design the implementation.Plan
- Mark.ts: Add
clearable?: boolean | (() => boolean)to theMarkConfiginterface, with defaulttrue. - ExtensionManager.ts: Track which marks are clearable (e.g., a
clearableMarkslist, or compute on demand). Actually, I'll compute the clearable mark names in the ExtensionManager similar tosplittableMarks. - unsetAllMarks.ts: Add
options?: { ignoreClearable?: boolean }parameter. WhenignoreClearableis false (default), skip marks that haveclearable: false. Also handlecan().unsetAllMarks()returningtruewhen only non-clearable marks present.
Let me first check the existing tests for commands to understand the test setup.
- Mark.ts: Add
Assistant
Now let me look at how the
canworks to understand how theunsetAllMarkscommand'scan()returns. Let me check the createCan function.Assistant
Assistant
Let me look at the
unsetMarkcommand for comparison on how it handles empty selection and stored marks.Assistant
I now have a clear understanding. Let me implement the changes. First, add the
clearablefield toMarkConfiginMark.ts.Assistant
No python. Let me use the edit command instead.
Assistant
Now let me add the
clearableMarksproperty to ExtensionManager.Assistant
Now let me update the
setupExtensionsmethod to populateclearableMarks. Let me look at the mark branch again.Assistant
Let me check the destroy method to see if
splittableMarksis reset there, and addclearableMarkstoo.Assistant
The destroy method doesn't reset
splittableMarkseither, so I'll keep consistency. Now let me update theunsetAllMarks.tscommand.Assistant
Let me verify
editoris part of theCommandPropstype.Assistant
editorandstateare both available. Now let me build the core package and run a typecheck/test to verify.Assistant
Let me write a temporary test script to reproduce the issue and verify the fix. First, let me check how tests reference
@tiptap/core.Assistant
Let me create a temporary test spec to reproduce and verify the fix.
Assistant
All 5 tests pass. Now let me run the broader core test suite to make sure I didn't break anything.
Assistant
All tests pass. Let me also run a typecheck to ensure types are correct. Let me check if there's a typecheck setup.
Assistant
These are pre-existing demo errors unrelated to my changes. Let me filter for errors only in the core package.
Assistant
These errors are in
transformPastedHTML.test.tsand unrelated to my changes. Let me verify they're pre-existing by stashing my changes and re-running.Assistant
Confirmed — those errors are pre-existing (20 errors before my change too). My changes introduce no new type errors. Let me double check my specific files have no type errors.
Assistant
My changes are type-clean. Now let me remove the temporary test file before submitting (per instructions not to add tests).
Assistant
Let me review the final diff of my changes.
Assistant
Let me run the full core test suite once more (without the temp test) to confirm no breakage.
Assistant
All 410 tests pass. Let me check if any other extensions reference
unsetAllMarks(e.g., a clear-formatting command) that might need awareness of this change.Assistant
Let me also check the
extensionspackage for any "clear formatting" command that might callunsetAllMarks.Assistant
Let me verify the bug actually existed before my fix by temporarily reverting
unsetAllMarks.tsand re-running a reproduction test.Assistant
Confirmed — the bug is reproduced on the unfixed code (the comment mark is deleted). Now let me restore my fix and re-run to confirm it passes.
Assistant
The fix works. Now let me clean up the temporary reproduction test file.
Assistant
Let me do a final full core test run to confirm everything is clean.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.