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 analyze the issue:
- The issue is about
unsetAllMarksdeleting comments when it shouldn't - The solution requires implementing a
clearableconfiguration option for marks - Marks with
clearable: falseshould be preserved whenunsetAllMarksis called - The
unsetAllMarkscommand should accept anignoreClearableoption
Let me first explore the repository structure to understand the codebase.
- The issue is about
Assistant
Let me explore the core package structure to find the relevant files mentioned in the interface section.
Assistant
Let me explore the core package to find the Mark.ts and unsetAllMarks.ts files.
Assistant
Let me read the key files: Mark.ts, unsetAllMarks.ts, and understand the current implementation.
Assistant
Now let me look at the unsetAllMarks command and related files.
Assistant
Now I need to understand the full picture. Let me look at:
- The types file to see how Commands interface is defined
- The can() method for unsetAllMarks
- How marks are currently handled
Let me explore more files to understand the complete implementation.
Assistant
Let me search for the relevant parts of the types file and understand the Commands interface better.
Assistant
Let me search for how unsetAllMarks is used and find the can() implementation:
Assistant
Let me look at how the can() method works:
Assistant
Let me look at the CommandManager.ts to understand how can() works:
Assistant
Let me look at existing tests for unsetAllMarks:
Assistant
I'll try a different approach to find test files related to unsetAllMarks.
Assistant
Let me look at the extension-link to understand how marks are configured:
Assistant
Let me look at how the commands are structured and how marks can be removed:
Assistant
Let me look at how setMark and unsetMark work:
Assistant
Now I have a good understanding. Let me look at unsetMark:
Assistant
Now let me check the comments extension and how the core index exports work:
Assistant
Let me check how tests are run and look for existing tests related to marks:
Assistant
Let me look at how to access mark configuration from the schema/extensions:
Assistant
Let me check how marks are stored and accessed to understand how to get the
clearableconfig:Assistant
Good -
clearabledoesn't exist yet, confirming I need to implement it. Let me understand the extension manager better to see how mark configurations are accessed:Assistant
Now I have a comprehensive understanding of the codebase. Let me outline my plan:
Plan:
- Add a
clearableconfiguration option to theMarkConfiginterface inMark.ts(default:true) - Update the
unsetAllMarkscommand to:- Accept
options?: { ignoreClearable?: boolean } - Check each mark's
clearableconfig and skip non-clearable marks unlessignoreClearableis true
- Accept
- Handle both
booleanand() => booleanfor theclearableoption
Let me start implementing:
- Add a
Assistant
Let me explore how to access mark configuration from the schema:
Assistant
Let me look at the ExtensionManager to see how to access mark configurations.
Assistant
Let me understand how ProseMirror marks work. When you have a mark in the document, you can access its type via
mark.type. The type has aspecproperty that contains the mark spec. Let me check if there's a way to access theclearableconfig from the mark type spec.The key insight is that:
- Each mark extension has a configuration stored in
this.optionswhen the extension is created - When the schema is built, the mark type's
specis populated with the options - So
mark.type.specshould contain the mark's configuration
Let me check how the schema is built.
- Each mark extension has a configuration stored in
Assistant
Let me continue exploring to understand how the mark specs are set up.
Assistant
Let me look at how marks are registered with the schema in the editor. The ProseMirror mark type has a
specproperty that contains the mark's configuration.Assistant
Now I understand the architecture better. Let me look at how ProseMirror stores mark specs and how we can access the
clearableconfiguration from a mark instance.The key insight is:
- Mark extensions are registered in the schema
- When we have a
ProseMirrorMarkinstance, we can accessmark.typewhich is aMarkType - The
MarkTypehas aspecproperty that contains the mark's spec/options - We need to add
clearableto the mark's spec so it's accessible
However, looking at the code more carefully, the mark spec in ProseMirror doesn't automatically include Tiptap-specific options like
clearable. We need to either:- Store the
clearableconfig in the mark spec - Or look it up from the extension storage/extensions list
Let me check how ProseMirror mark specs work.
Assistant
Now I understand the architecture. Let me search for how the schema marks are built:
Assistant
Let me look at how the ProseMirror schema is created for marks. The mark type spec is used to create the mark type in ProseMirror, and we can access it via
mark.type.spec.Assistant
Assistant
Let me continue exploring how mark specs are built:
Assistant
Now I have a complete understanding of the codebase. Let me implement the solution:
- Add
clearabletoMarkConfiginMark.ts - Add
clearableto the mark schema ingetSchemaByResolvedExtensions.ts - Update
unsetAllMarkscommand to respectclearablemarks
- Add
Assistant
Now I have a complete understanding. Let me implement the solution step by step.
Step 1: Add
clearabletoMarkConfiginterface inMark.tsAssistant
Now let me add the
clearableoption to Mark.ts. I'll add it after thecodeproperty and beforeparseHTML.Assistant
I need to use the proper edit command format. Let me view the file first to understand the exact line numbers, then edit it properly.
Assistant
Let me use the bash terminal to edit the files.
Assistant
Let me insert the clearable option after line 102 (after the code property's closing) and before line 104 (the Parse HTML comment).
Assistant
I need to insert the clearable option after line 102 (after the code property) and before line 104 (the Parse HTML comment). Let me use sed to insert the new content.
Assistant
Let me verify the change:
Assistant
Good, but there's a missing blank line before "Parse HTML". Let me fix that:
Assistant
I need to add a blank line before the Parse HTML comment. Let me fix that:
Assistant
Now let me verify the fix looks good and then move on to the next step: adding
clearableto the mark schema ingetSchemaByResolvedExtensions.ts.Assistant
Good, the Mark.ts file now has the
clearableoption properly formatted. Now let me move to Step 2: Addclearableto the mark schema ingetSchemaByResolvedExtensions.ts.Assistant
Let me see the context around line 199:
Assistant
Now I need to add
clearableto the mark schema. Let me add it aftercode(line 199):Assistant
Let me verify:
Assistant
Now let me update Step 3: Update the
unsetAllMarkscommand to respect theclearableoption.Assistant
Now I need to update the
unsetAllMarkscommand to respect theclearableoption. Let me rewrite the entire file with the proper implementation:Assistant
Now let me verify the implementation looks correct:
Assistant
Let me now run the existing tests to make sure the changes don't break anything:
Assistant
Let me check if there are any existing tests and how to run them:
Assistant
Let me try to build and run tests to verify my changes work correctly:
Assistant
The test command timed out. Let me try to build the core package first to verify TypeScript compilation, or write a simple test script to verify the changes work.
Assistant
Let me continue running the tests to verify everything passes:
Assistant
All 410 tests pass. Now let me verify the TypeScript compilation is working:
Assistant
The TypeScript errors are all from demo files and node_modules, not from the core package I modified. Let me verify my changes compile correctly:
Assistant
The TypeScript errors are all pre-existing and related to the project's TypeScript configuration (ES version settings, module resolution, etc.) - not specific to my changes. The important thing is that all 410 tests passed.
Let me verify my changes are complete:
Assistant
Let me view the full diff to verify the changes:
Assistant
Let me verify the changes by writing a simple test script to confirm the fix works correctly:
Assistant
Let me run the tests once more to confirm everything works:
Assistant
All tests pass (410 tests, 38 test files). Let me provide a summary of the changes made:
Summary of Changes
I implemented the
clearableconfiguration option for marks to preventunsetAllMarksfrom deleting semantic marks like comments.Files Modified:
-
packages/core/src/Mark.ts- Added theclearableoption toMarkConfiginterface:- Type:
boolean | (() => boolean) - Default:
true(implicit - marks without explicitclearable: falseare clearable) - This allows mark extensions to specify they should be preserved during clear-formatting operations
- Type:
-
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.