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
I'll start by exploring the repository structure to understand the codebase and locate relevant files. Let's first check the root directory.
- Assistant
Let me look at the structure of the repository to understand how it's organized.
- Assistant
Let me explore the packages directory to find the relevant files.
- Assistant
Now let me look at the relevant files mentioned in the issue: Mark.ts and unsetAllMarks.ts.
- Assistant
Let me examine the current implementation of both files.
- Assistant
Now let me examine Mark.ts to understand the Mark configuration.
- Assistant
Let me check if there's a comments extension in the packages:
- Assistant
The comments extension isn't directly in the packages directory. Let me check for extension-comments or similar.
- Assistant
Good. The comments extension isn't in the main packages. The core fix needs to be in the core
Mark.tsandunsetAllMarks.tsfiles. Let me understand the issue:- Add a
clearableoption toMarkConfig(defaulttrue) - Modify
unsetAllMarksto only remove clearable marks unlessignoreClearable: trueis passed can().unsetAllMarks()must returntruewhen only non-clearable marks exist
Let me check how
can()works in the commands framework: - Add a
- Assistant
Let me check how commands handle the
dispatchpattern: - Assistant
Now let me understand how
tr.removeMarkworks to see how we can filter marks: - Assistant
Let me understand the current implementation. I need to:
- Add
clearableoption toMarkConfiginMark.ts- should default totrue - Modify
unsetAllMarksto accept options{ ignoreClearable?: boolean }and only remove marks that are clearable (or all ifignoreClearableis true)
Let me also check how the
unsetMarkcommand works and how marks are accessed in the state. - Add
- Assistant
Let me look at how mark types are accessed in the state:
- Assistant
Let me look at how the editor accesses mark configurations:
- Assistant
Let me look at the types to understand how the command context provides access to editor and marks.
- Assistant
Let me understand what properties are available in the command callback:
- Assistant
Let me look at CommandProps to see what properties are available:
- Assistant
Now let me understand how mark types are stored in the editor and how to get their config:
- Assistant
Let me check how editor gets access to mark extension types and check the
state.schema.marks: - Assistant
Now let me look at how to get all mark types and their extension configurations:
- Assistant
Let me look at the editor's schema to understand how mark types are stored:
- Assistant
Let me look at how the extensionManager is structured:
- Assistant
Let me look at the ExtensionManager to understand how mark extensions are stored and their configs accessed:
- Assistant
Let me look at how mark extensions are resolved:
- Assistant
Let me check how to access mark extension configs from within commands:
- Assistant
Now I need to understand how to get a Mark's extension config from the editor context, specifically to check the
clearableproperty. Let me look at how the editor stores extension information: - Assistant
Let me look at how the Mark extension stores configuration:
- Assistant
Let me look at how
getExtensionFieldworks and how mark extensions are resolved: - Assistant
Let me look at how
keepOnSplitis accessed and used in the ExtensionManager, since it follows a similar pattern to what we need forclearable: - Assistant
Let me understand how the Editor accesses extensions:
- Assistant
Now let me understand how to resolve the
clearableproperty from within a command. The command has access toeditorandstate. I need to check if each mark type in the selection is clearable. Let me look at how to map mark types to extensions: - Assistant
Now let me look at how to get mark extensions from the editor:
- Assistant
Let me look at the splitExtensions helper and how to get mark extensions:
- Assistant
Now let me look at how the editor accesses extensions and their configurations:
- Assistant
Now I have a good understanding of the codebase. Let me plan the implementation:
- Add
clearableoption toMarkConfiginMark.ts - Modify
unsetAllMarksto accept options and respect theclearableproperty - Update the type declarations
Let me first check how to get the editor's extension manager and mark extensions from within a command:
- Add
- Assistant
Now let me look at the existing tests for
unsetAllMarksand related functionality: - Assistant
Let me try a different approach to find tests.
- Assistant
Let me also check existing tests and the
callOrReturnutility: - Assistant
Now let me check how
tr.removeMarkworks in ProseMirror - it can accept a specific mark type to remove: - Assistant
Let me understand the
removeMarkAPI from ProseMirror to see if it can filter by mark type: - Assistant
Let me look at the Extendable class to understand how config options are resolved:
- Assistant
Now I have a good understanding of the codebase. Let me plan the implementation:
- Add
clearableoption toMarkConfiginMark.tswith a default oftrue - Modify
unsetAllMarksto accept options{ ignoreClearable?: boolean }and only remove marks that are clearable (unlessignoreClearableis true) - Update the command declaration to include the options parameter
Let me also check how marks are accessed in the state to understand how to filter them:
- Add
- Assistant
Let me look at how
getMarkTypeworks: - Assistant
Now I have a good understanding of the codebase. Let me plan the implementation:
- Add
clearableoption toMarkConfiginMark.ts(defaulttrue) - Modify
unsetAllMarksto accept options{ ignoreClearable?: boolean }and only remove marks that are clearable (unlessignoreClearableis true) - Update the command type declarations accordingly
The key challenge is: how do we know which marks are "clearable"? We need to:
- Iterate through all mark types in the schema
- For each mark type, check if the corresponding Mark extension has
clearable: false - Only remove marks that are clearable (or all marks if
ignoreClearableis true)
Let me look at how to access the editor's extensions from within a command:
- Add
- Assistant
Now I understand the full picture. Let me implement the changes:
- Mark.ts: Add
clearableoption toMarkConfiginterface - unsetAllMarks.ts: Modify to accept options and check mark clearable status
- Need to figure out how to access mark config from within the command
The key challenge is: how does
unsetAllMarksknow which marks are clearable? It needs to access the Mark extension's config. Looking at the code, the command receives{ tr, dispatch, editor, state }. Theeditor.extensionManager.extensionsgives us access to all extensions.For each mark type in the schema, we need to find the corresponding Mark extension and check its
clearableproperty. Theclearableproperty can be a boolean or a function (similar tokeepOnSplit).Let me look at how
keepOnSplitis used in the codebase to understand the pattern: - Mark.ts: Add
- Assistant
Now I have a good understanding of the codebase. Let me implement the changes. First, let me add the
clearableoption toMarkConfiginMark.ts: - Assistant
Now let me add the
clearableoption afterkeepOnSplit: - Assistant
Now let me add the
clearableoption toMarkConfig: - Assistant
Now let me add the
clearableoption afterkeepOnSplit: - Assistant
Now let me add a blank line after the clearable declaration:
- Assistant
Good, the
clearableoption has been added toMarkConfig. Now I need to modifyunsetAllMarks.tsto accept options and respect theclearableproperty. - Assistant
Now I need to understand how to access mark extension configs from within a command. Let me look at how to get extensions by mark type:
- Assistant
Now I need to think about how to implement the logic in
unsetAllMarks. Let me look at howgetExtensionFieldis used in the extension manager to understand what context is needed: - Assistant
Now I have all the information I need. Let me implement the changes. First, let me update
unsetAllMarks.ts: - Assistant
Now I need to modify
unsetAllMarksto:- Accept options:
{ ignoreClearable?: boolean } - When
dispatchis called:- If
ignoreClearableis true, remove all marks (current behavior) - Otherwise, only remove marks that are clearable (default behavior)
- If
- The
can().unsetAllMarks()should return true when the selection contains only non-clearable marks (successful no-op)
The key challenge is: how to determine which marks are clearable within the command?
In the command context, we have access to
editor(from CommandProps), which hasextensionManager.extensions. We can iterate over the mark extensions and check theirclearableproperty usinggetExtensionFieldandcallOrReturn.Let me look at how to get mark extensions from the editor:
- Accept options:
- Assistant
Now I need to understand how to get the mark extensions from the editor to check their
clearableproperty. Let me look at how the editor's extensionManager stores extensions and how to access them: - Assistant
Now let me implement the changes to
unsetAllMarks.ts. I need to:- Update the type declaration to accept options
- Modify the implementation to check mark's
clearableproperty - Use
editor.extensionManagerto find mark extensions and their configs
- Assistant
Now let me verify the changes by checking the build and running any existing tests:
- Assistant
Let me verify my understanding of
editor.extensionStorageto make sure the code is correct: - Assistant
Let me also check how the
editor.extensionStorageproperty is typed and what it provides. Let me also look at how the storage property is accessed elsewhere: - Assistant
Let me check if there are any existing tests for unsetAllMarks:
- Assistant
Let me check if there are any tests to run:
- Assistant
Let me also check if there are any existing tests that could be affected:
- Assistant
Let me check if there are test configurations and how to run tests:
- Assistant
Now let me create a test script to verify the changes work correctly:
- Assistant
Let me try to run the test to see if the implementation works:
- Assistant
Let me try building the project first to verify no compilation errors:
- Assistant
Those are pre-existing errors in demos. Let me check just the core package:
- Assistant
These are pre-existing test errors. Let me check if my changes have any TypeScript errors specifically:
- Assistant
Let me fix the TypeScript error:
- Assistant
I need to fix the TypeScript error on line 42:
editor.extensionStorage[markExtension.name]has an implicitanytype becauseStorageis a generic type that doesn't support string indexing. Let me fix this by using type casting. - Assistant
Now let me verify the TypeScript compilation again to make sure the error is fixed:
- Assistant
Let me also check the Mark.ts file:
- Assistant
Good, no TypeScript errors. Now let me run the existing tests to make sure my changes don't break anything:
- Assistant
All 38 test files passed (410 tests). No existing tests were broken by my changes. Let me also check if there are any tests in other packages that might test unsetAllMarks or the marks behavior:
- Assistant
Let me also check how
ParentConfighandles theclearableproperty. Let me look at the types file: - Assistant
Let me check the types.ts to see how
keepOnSplitis handled inParentConfig: - Assistant
Let me check
ParentConfigto see if I need to addclearablethere: - Assistant
Let me check the ParentConfig type to see if clearable needs to be added there.
- Assistant
The
ParentConfigtype is a mapped type that automatically derives from the config type, soclearableshould automatically be included. No changes needed totypes.ts.Let me verify the current state of both files:
- Assistant
Let me verify the clearable option location in Mark.ts:
- Assistant
Good. Both files look correct. Now let me also check if the exports are correct and run any additional tests that might be affected:
- Assistant
Let me check if MarkConfig is exported:
- Assistant
Good, MarkConfig is exported from Mark.ts which is re-exported from index.ts. Now let me run a broader set of tests to make sure nothing is broken:
- Assistant
All 117 test files passed (1064 tests). My changes don't break any existing tests.
Let me now verify my implementation handles all the edge cases from the evaluation contract:
- Marks are clearable by default - ✓ (default
truewith?? true) - A mark configured with
clearable: falsemust surviveunsetAllMarks()- ✓ unsetAllMarks({ignoreClearable: true})removes it - ✓can().unsetAllMarks()returns true when selection contains only non-clearable marks (successful no-op) - ✓unsetMarkmay still remove a non-clearable mark - ✓ (we didn't changeunsetMark)
Let me verify the final state of both files:
- Marks are clearable by default - ✓ (default
- Assistant
Let me also verify the final state of the Mark.ts file:
- Assistant
Both files look good. Let me now verify the complete diff of my changes:
- Assistant
The diff looks clean and correct. Let me run the full test suite one more time to make sure everything is solid:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.