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
Now I understand the structure. The
clearableconfig option is a Tiptap-specific thing (not a ProseMirror MarkSpec field), so it shouldn't go into the schema. Instead, theunsetAllMarkscommand needs to check theclearablefield of each mark extension to decide whether to remove the mark.Let me look at how to access mark extensions from within the command. The command has access to
tr,dispatch. Let me check the command signature and what's available (editor, state, etc.).Assistant
Now I understand the pattern. I need to:
- Add
clearableconfig option toMarkConfiginMark.ts. - Modify
unsetAllMarkscommand to check theclearablefield and skip marks that are not clearable (unlessignoreClearable: trueis passed). - Update the command type declaration to include the options.
Let me look at how the command can access extensions. The command has access to
editor, andeditor.extensionManager.extensions. Let me check how to get the mark type from the schema and the clearable config.Let me look at how
getExtensionFieldis used and how I can access theclearableconfig of a mark extension within the command.Actually, a simpler approach: I can access
editor.extensionManager.extensions, filter for mark extensions, and check theclearableconfig. But theclearableis a config field that usescallOrReturnviagetExtensionField. Let me check howgetExtensionFieldworks.- Add
Assistant
Now I have a good understanding. Let me look at the existing tests for unsetAllMarks and the commands directory structure.
Assistant
Now let me look at the commands index and how commands are structured, especially how
canworks for a command. Let me also look at theunsetAllMarkscommand more carefully and understand thecan()behavior.Let me look at how
canis implemented.Assistant
Let me look at how the command can access extensions and the schema, and check existing usages of getExtensionField in commands.
Assistant
Now let me look at the full ExtensionManager fields and setupExtensions to follow the
splittableMarkspattern.Assistant
Let me implement the changes. First, add the
clearableconfig toMark.ts(afterkeepOnSplit).Assistant
I'll add the
clearableconfig afterexitable. Let me use the edit command.Assistant
Now let me add the
clearableMarksfield to ExtensionManager. Let me view the field declarations andsetupExtensions.Assistant
Now let me populate
clearableMarksinsetupExtensions, right after thesplittableMarkslogic.Assistant
Let me check whether
setupExtensionsis called more than once (e.g., on reconfigure) and whethersplittableMarksgets reset, to mirror the same behavior forclearableMarks.Assistant
setupExtensionsis only called once in the constructor, andsplittableMarksis never reset. I'll mirror the same pattern. Let me add theclearableMarkspopulation right after thekeepOnSplitblock.Assistant
MarkConfigis already imported in ExtensionManager. Let me verify and now update theunsetAllMarkscommand.Assistant
Now let me update the
unsetAllMarkscommand.Assistant
Now let me verify the build and run a reproduction. First, let me check the test setup and how tests are run.
Assistant
Tests use source via aliases. Let me look at an existing test to understand the editor setup, then write a temporary reproduction test.
Assistant
Now let me create a temporary reproduction test.
Assistant
All 5 tests pass. Now let me run the existing core tests to ensure I didn't break anything.
Assistant
All 382 tests pass. Now let me check if there's an
extension-commentspackage that should setclearable: false.Assistant
No comment extension package exists in the repo. The fix is in core. Let me check if there's a
Commentmark definition referenced anywhere in tests/demos.Assistant
Let me verify the demos that call
unsetAllMarks()still work with the new optional parameter (they pass no args, defaulting to{}).Assistant
Let me verify
cleanUpSchemaItemto make sureclearabledoesn't leak into the ProseMirror schema spec.Assistant
cleanUpSchemaItemonly operates on the explicit object with specific schema fields, soclearablewon't leak into the ProseMirror MarkSpec. Now let me run the linter on my changed files.Assistant
No lint errors. Now let me run a TypeScript type check on the core package to make sure types are correct.
Assistant
Let me check the full tsc output to confirm no new errors were introduced (filtering to my files showed none).
Assistant
The errors shown are all pre-existing and unrelated (static-renderer, vue-3 tests, vitest.config). Let me confirm there are zero errors in the core
srcfiles I touched.Assistant
These errors are in
transformPastedHTML.test.ts— unrelated to my changes (abouttransformPastedHTMLargument count). Let me confirm they're pre-existing by checking against a clean checkout of just that test area, and verify my actual changed files compile cleanly.Assistant
Confirmed — those
transformPastedHTMLerrors are pre-existing and unrelated to my changes. My changes introduce no new TypeScript errors.Now let me run a broader set of extension tests (bold, italic, link, etc.) to ensure nothing broke.
Assistant
All passing. Let me verify
state.schemais accessible in the command props (viacreateChainableState).Assistant
state.schemais available. My reproduction tests already confirmed this works in practice. Let me also do a broader search to see if there's any comment-mark definition in the repo that should setclearable: false.Assistant
No
extension-commentspackage exists in this repo (the only matches are description strings). The fix lives entirely in core. Now let me remove the temporary test file and do a final review.Assistant
The diff is clean and complete. Let me run the core test suite once more in the final state to confirm everything passes.
Assistant
All 377 tests pass. To be thorough on the checklist (reproducing the original bug), let me temporarily stash my fix and confirm the original behavior deletes a non-clearable mark.
Assistant
The reproduction confirms the original bug: with the original code, after
unsetAllMarks(), the comment mark is removed (marks: []). My fix (verified earlier with temp tests) makes aclearable: falsecomment survive.Let me do a final check that no temp files remain and only the 3 intended files are modified.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.