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.jseditor.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 get an overview.
- Assistant
Let me explore the repository structure and understand the codebase better, particularly focusing on the marks system and the
unsetAllMarkscommand. - Assistant
Let me look at the extension-comments package (if it exists) and the Mark.ts and unsetAllMarks.ts files.
- Assistant
Now let me look at the Mark.ts file to understand the Mark configuration structure.
- Assistant
Now let me look at the comments extension to understand how it's implemented.
- Assistant
The comments extension doesn't seem to exist in this repository. Let me check if there's an existing test file for unsetAllMarks.
- Assistant
Let me explore the repo more to understand the testing infrastructure.
- Assistant
Now I need to understand the issue:
unsetAllMarks()currently removes ALL marks from the selection (usingtr.removeMark()which removes all marks)- The fix needs to:
- Add a
clearableoption toMarkConfig(default:true) - Modify
unsetAllMarksto only remove marks that haveclearable: true - Add
ignoreClearableoption tounsetAllMarksto force-removing all marks
- Add a
Let me look at how marks work in ProseMirror/Tiptap and how to check mark configuration.
- Assistant
Let me look at how the editor accesses mark types and how we can get the mark configuration.
- Assistant
So
tr.removeMark(from, to)without a type argument removes all marks. We need to change this to iterate through mark types and only remove clearable ones.Let me look at the
Editorclass to see how to access mark types/extensions. - Assistant
Now I need to understand how to access mark types and their configuration in the editor context.
- Assistant
Let me understand the command context better - what's available in the
RawCommandsfunctions: - Assistant
Let me look at the RawCommands type and the command context:
- Assistant
Let me look at the RawCommands type definition to understand what's available in command functions.
- Assistant
Let me look at the Command type definition to understand what parameters are passed to commands.
- Assistant
Now I understand the structure. The command receives
editor,state,tr, etc. So I can accessstate.schemato get mark types and their extensions' options.Let me look at how the editor stores extension configurations. The key is that each mark extension has a
MarkConfigwhich would include theclearableproperty once we add it. I need to check how to access that configuration from within the command context.Let me look at how other commands access editor extensions.
- Assistant
Now I understand the structure. Let me look at how mark extensions are stored and accessed to understand how to check their configuration.
- Assistant
Now let me look at how extensions store their options and how to access mark configurations. Let me also check how the
clearableproperty could be resolved: - Assistant
Let me understand how mark extensions are organized and how to get configuration from a mark type:
- Assistant
Now let me look at how we can access mark extensions from the editor. Let me check how marks are stored in the schema and how to map from a mark type to the extension configuration.
- Assistant
Now I have a good understanding of the codebase. Let me plan the changes needed:
- Add
clearableoption toMarkConfiginMark.ts(supportsboolean | (() => boolean), defaulttrue) - Update
unsetAllMarkscommand to accept{ ignoreClearable?: boolean }and filter marks - Access the mark extensions through the editor's extension manager to check
clearableconfig
Let me also check how mark types are accessed from extensions and how
splitExtensionsworks: - Add
- Assistant
Now let me look at how to get mark extensions from the editor state to check clearable config:
- Assistant
Now I have a good understanding of the codebase. Let me check how the
callOrReturnutility works and then implement the solution: - Assistant
Now I understand everything I need. Let me implement the solution. First, let me add the
clearableoption toMarkConfig: - Assistant
Now I'll add the
clearableoption to the MarkConfig interface. Let me find a good place to add it - I'll add it after theexitablefield: - Assistant
Good. Now let's update the
unsetAllMarkscommand. First let me check how to access extension configuration from a mark type name: - Assistant
Now I need to understand how to access mark extensions in the
unsetAllMarkscommand. The command receives{ editor, tr, dispatch, state }so I can useeditor.extensionManagerto access extensions.Let me now implement the
unsetAllMarkscommand: - Assistant
Now let me understand how the command receives the editor context. Let me look at the Command type:
- Assistant
Good. Now I understand the full structure. Let me implement the changes:
- First, update the
unsetAllMarkscommand to accept options and filter marks based onclearableconfig - The command has access to
editorwhich hasextensionManagerwith all extensions
Let me look at how to get mark extensions and check their clearable config:
- First, update the
- Assistant
Let me check how to find the extension for a specific mark type. I need to check for each mark type whether it's clearable or not.
- Assistant
Let me look at how mark extensions can be identified from a mark type:
- Assistant
Now I have a good understanding. Let me implement the changes. First, let me check how we can access mark extensions and check clearable property from within a command:
- Assistant
Now I have a good understanding. Let me check how ProseMirror's
removeMarkworks - does it take an optional mark type parameter? - Assistant
I see from the
unsetMarkcommand thattr.removeMark(from, to, type)removes a specific mark type. So I can iterate over all mark types and selectively remove only clearable ones.Now let me implement the full solution. First, let me update the
unsetAllMarkscommand: - Assistant
Now let me understand how to access the
clearableproperty from a mark extension within the command. I need to look at how thegetExtensionFieldworks with the context. - Assistant
Now I need to understand how to map mark types to their extensions. Let me check the schema and extension relationship:
- Assistant
Let me check how to determine if a mark type is clearable by looking at how other similar checks are done in the codebase. Let me look at
keepOnSplitfor an example: - Assistant
Now I understand the pattern. Let me implement the solution. I need to:1. Update
unsetAllMarksto acceptoptions?: { ignoreClearable?: boolean }2. For each range, check each mark type in the schema and selectively remove only clearable onesLet me first check how to access mark types and extensions from within the command: - Assistant
Now let me implement the full solution. First, update the
unsetAllMarkscommand: - Assistant
Now let me verify the imports are correct. Let me check that
splitExtensionsis exported from the helpers: - Assistant
Now let me check if we also need to export
splitExtensionsfrom the core package: - Assistant
Now let me check if the
clearableproperty should also be exported/referenced from the main index file: - Assistant
Good,
Mark.tsis already exported from the index. Now let me verify the implementation is correct. Let me also check if there's an existing test forunsetAllMarks: - Assistant
Let me look at existing tests to understand the testing patterns:
- Assistant
Now let me run the existing tests to see if our changes break anything:
- Assistant
Let me wait for the tests to complete. Let me run them again with a timeout and check for failures.
- Assistant
All 377 tests pass. Now let me verify the
can()behavior. The evaluation contract says:can().unsetAllMarks()returnstruewhen the selection contains only non-clearable marks. Let me look at howcan()works: - Assistant
Good, the
can()mechanism works by calling the command withdispatch = undefined. Our implementation returnstruewhen dispatch is undefined, which is correct per the evaluation contract.Now let me verify the import of
splitExtensionsis correct: - Assistant
Let me verify all imports are correct:
- Assistant
Let me also verify the
callOrReturnutility: - Assistant
Now let me create a test script to verify the implementation works correctly:
- Assistant
Let me run this test to verify the implementation:
- Assistant
I need to place the test file within the packages directory. Let me create it in the core test directory.
- Assistant
Wait, I need to be careful - the instructions say I shouldn't add tests to the repository. Let me use a temporary script approach:
- Assistant
Let me write a simple test script that uses the Editor API directly:
- Assistant
Let me create a temporary test file outside the packages directory to test:
- Assistant
Let me run the test with a custom include pattern:
- Assistant
Let me create a temporary config to include the test file:
- Assistant
Let me put the test file inside the packages directory structure:
- Assistant
All 6 tests pass! Now let me clean up the temporary test file and run the full test suite to make sure nothing is broken:
- Assistant
Let me run the full test suite to make sure nothing is broken.
- Assistant
All 377 tests still pass. Now let me review the changes I've made and verify they look correct:
- Assistant
Now let me verify the Mark.ts changes:
- Assistant
Let me fix the open command.
- Assistant
Now let me verify the complete diff of changes:
- Assistant
Now let me run the full test suite one more time to make sure everything passes:
- Assistant
All 377 tests pass. Let me now review the changes one more time and verify they match the evaluation contract:
- Assistant
Now let me verify the changes match the evaluation contract:
- Marks are clearable by default ✓ - Marks without explicit
clearable: falseare clearable (default behavior unchanged) clearable: falsemark survivesunsetAllMarks()✓ - We checkclearable === falseand skip those marksunsetAllMarks({ignoreClearable: true})removes all marks ✓ - WhenignoreClearableis true, we remove all markscan().unsetAllMarks()returnstrueon non-clearable marks ✓ - Returns true even when dispatch is undefinedunsetMarkstill removes non-clearable marks ✓ -unsetMarkis unchanged
Let me also verify the storage type usage is correct by checking how other code accesses it:
- Marks are clearable by default ✓ - Marks without explicit
- Assistant
Let me check what
Storagetype is and align my code: - Assistant
Let me simplify the type assertion to match the pattern used elsewhere:
- Assistant
Let me fix the storage access to match the pattern used in the ExtensionManager:
- Assistant
The implementation looks correct as-is. Let me verify there are no TypeScript compilation issues:
- Assistant
Let me find the tsconfig.
- Assistant
Let me check the root tsconfig:
- Assistant
Those TypeScript errors are from pre-existing demo code, not from our changes. Let me check specifically if there are errors in the packages/core directory:
- Assistant
Those are pre-existing errors in tests, not related to our changes. Let me verify none of our changed files have TypeScript errors:
- Assistant
No TypeScript errors in our changed files. Let me also verify the test suite one more time with all tests:
- Assistant
All 1064 tests pass across 117 test files. Now let me go through the checklist:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.