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
Let me start by understanding the issue and the repository structure. The issue is about
unsetAllMarksdeleting comments when it shouldn't. The solution involves:- Adding a
clearableoption to Mark configuration - Modifying
unsetAllMarkscommand to respect theclearableoption - Non-clearable marks should survive
unsetAllMarks()unlessignoreClearable: trueis passed
Let me first explore the repository structure to understand how it's organized.
- Adding a
Assistant
Let me explore the repository structure and the key files I need to modify.
Assistant
Now let me look at the
unsetAllMarkscommand:Assistant
Now let me look at the types file to understand the command interface:
Assistant
Let me look at the commands directory to understand how commands are structured:
Assistant
Now let me look at how other commands are structured, especially those that have options. Let me also check how to access extension configuration from within commands:
Assistant
Now let me look at the Extendable class to understand how extension configs are handled and how to get mark configuration:
Assistant
Let me check how the Editor class works to understand how to access mark extensions from within commands:
Assistant
Let me look at the ExtensionManager to understand how to access mark configurations:
Assistant
Let me look at how to get extensions from the editor state and how to get extension configuration:
Assistant
Now let me look at the helpers to understand how to access extensions from the editor:
Assistant
Now let me look at how the tests are structured and find existing tests for unsetAllMarks:
Assistant
Found some spec files, let me look at them to understand the test structure
Assistant
Let me look at an existing test file to understand the test structure:
Assistant
Now let me look at the UnionCommands type to understand how commands are defined:
Assistant
Now let me check the index.ts to understand the exports:
Assistant
Let me understand how commands are registered and dispatched, especially looking at CommandManager:
Assistant
Now I understand the structure. Let me look at how to access mark configuration from within a command. The key is that in the command function, we have access to
statewhich contains the editor's state. From there, we can get mark types and their configurations.Let me check how extensions are accessed from the editor:
Assistant
Now I understand the structure. Let me plan my implementation:
- Add
clearabletoMarkConfiginMark.ts- This will be a configuration option that can beboolean | (() => boolean)with defaulttrue - Modify
unsetAllMarkscommand to:- Accept an optional
ignoreClearable?: booleanoption - When
ignoreClearableis false (default), only remove marks that haveclearable: true - When
ignoreClearableis true, remove all marks - Update the type declaration for the command
- Update the
can().unsetAllMarks()behavior to returntruewhen selection only contains non-clearable marks (successful no-op)
- Accept an optional
Let me also look at how to access the mark extension config from within a command. I need to find how to get the
clearablevalue for a given mark type:- Add
Assistant
Let me look at how other commands access the editor's extensions to get extension config:
Assistant
I need to understand how to get the mark extension from within a command. Let me look at how the CommandProps interface is defined and what's available.
Assistant
I need to understand the structure better. The
CommandPropshas access toeditor, and fromeditorI can accesseditor.extensionManager.extensionsto get all extensions. From there I can find the mark extension and get itsclearableconfig.Let me also check the
callOrReturnutility sinceclearablecan be a function.Assistant
Now I have enough information. Let me implement the changes:
- First, add the
clearableoption toMarkConfiginMark.ts - Update the
unsetAllMarkscommand to respect theclearableoption
Let me start:
- First, add the
Assistant
Now let me add the
clearableoption toMarkConfig. I'll add it after thecodeproperty since it's also a configuration option:Assistant
Now I'll add the
clearableoption toMarkConfig. I'll add it after thecodeproperty. Let me edit the file:Assistant
I see there's a duplicate line issue. Let me fix it:
Assistant
I need to fix the duplicate line at line 102. Let me fix it:
Assistant
I need to add an empty line between the
clearableproperty andparseHTMLfor consistency. Let me fix it:Assistant
Good, the Mark.ts file is now updated with the
clearableproperty. Now let me update theunsetAllMarkscommand to use this new option:Assistant
Now I need to rewrite the
unsetAllMarks.tsfile with the new implementation. The key changes are:- Accept an optional parameter
{ ignoreClearable?: boolean } - Get the list of clearable marks from the editor's extensions
- Only remove marks that are clearable (unless
ignoreClearableis true) - For
can().unsetAllMarks(), returntruewhen selection only contains non-clearable marks (successful no-op)
- Accept an optional parameter
Assistant
Wait, I have a bug in my logic. Let me re-read the requirements:
- Marks with
clearable: true(default) should be removed byunsetAllMarks() - Marks with
clearable: falseshould be preserved byunsetAllMarks()unlessignoreClearable: true
Let me fix the logic:
- Marks with
Assistant
Let me verify the changes I made and then test them. Let me check the file content first.
Assistant
I notice I have an unused import
MarkType. Let me fix that and also check if the implementation is correct. Let me also think about usingmarksBetweeninstead ofnodesBetweenfor a more reliable approach.Assistant
Let me verify the updated file and check if there are any issues:
Assistant
Let me verify the Mark.ts file looks correct and then try to build the project to check for any TypeScript errors.
Assistant
Now let me check the project structure to understand how to build and run tests:
Assistant
The files look correct. Now let me check if there are TypeScript compilation errors and run the existing tests to make sure my changes work correctly.
Assistant
The files look correct. Now let me check if there are TypeScript compilation errors and run the existing tests to make sure my changes work correctly.
Assistant
Let me try a different approach - check if the build system is already set up and try to run tests more directly.
Assistant
The tests pass. Now let me create a test script to verify that my implementation works correctly for the specific requirements:
Assistant
Let me run the test to verify my implementation works correctly.
Assistant
I need to move the test file to the correct location so vitest can find it. Let me create it in the packages/core/tests directory.
Assistant
I need to fix the import paths in my test file. Let me look at an existing test file to see how they import:
Assistant
I need to fix my test file to use the proper import paths. Let me update it.
Assistant
I need to fix the test file imports - let me use the correct package import paths that match the existing tests in the repository.
Assistant
Excellent! All 4 tests pass! Let me now run the existing tests to make sure I haven't broken anything:
Assistant
All existing tests pass. Let me run more tests to make sure nothing is broken:
Assistant
All 381 tests pass, including my 4 new tests. Let me also add some more edge case tests to make sure the implementation handles them correctly:
Assistant
Let me run the updated tests to make sure all edge cases pass.
Assistant
All 9 tests pass. Let me run the full test suite for the core package to make sure everything still works:
Assistant
All 386 tests pass. Now I need to remove my test file since I was instructed not to add new tests to the repository:
Assistant
Now let me verify that all original tests still pass and review my changes:
Assistant
Let me review all my changes:
Assistant
Let me verify the implementation is complete by reviewing the requirements and running a final test:
Assistant
Let me verify all my changes one more time and make sure everything is correct before submitting.
Assistant
Let me also verify the unsetAllMarks.ts file is correct:
Assistant
All changes look good. Let me verify the tests pass one final time and then submit.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.