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 this issue. The user is reporting that
unsetAllMarksdeletes comments in the TipTap editor. The solution is to:- Add a
clearableoption to Mark configuration (default:true) - Modify
unsetAllMarkscommand to respect this option - Allow
unsetAllMarks({ignoreClearable: true})to override the behavior
Let me start by exploring the repository structure to understand how it's organized.
- Add a
Assistant
Let me explore the repository structure more to understand how it's organized, particularly looking at the Mark.ts file and unsetAllMarks.ts file.
Assistant
Now let me look at the unsetAllMarks command to understand how it currently works.
Assistant
Now I need to understand how the command interface works. Let me look at the types file and how commands are structured.
Assistant
Now let me look at the RawCommands type definition to understand how unsetAllMarks is defined:
Assistant
Now let me look at how the commands are registered and understand the full structure:
Assistant
Now let me look at how the
can()method works to understand how it checks if commands can be applied:Assistant
I need to fix my grep command - the parentheses need escaping properly.
Assistant
Let me understand the command manager better:
Assistant
Now let me check how MarkConfig is used, particularly looking at how other configurable properties like
excludes,exitable, etc. are handled:Assistant
Let me look at the ExtensionManager to understand how these mark config properties are retrieved:
Assistant
Let me look at the
getExtensionFieldhelper function to understand how it works:Assistant
Now let me understand the tests structure for unsetAllMarks to see if there are existing tests:
Assistant
Now let me look at the existing tests in the can.spec.ts file to understand the testing patterns:
Assistant
Now I understand the codebase structure. Let me also look at how the ExtensionManager gets mark information:
Assistant
Now I need to understand how I can access mark configuration from the extension manager during unsetAllMarks. Let me check what's available in the editor state:
Assistant
Let me look at how the extensionManager stores mark names and how to access extension info from the commands:
Assistant
Let me look at how commands get access to the editor and how to check mark configuration:
Assistant
Now I have a good understanding of the codebase. Let me plan my implementation:
-
Add
clearableoption toMarkConfigin/tiptap/packages/core/src/Mark.ts- This should beboolean | (() => boolean)with defaulttrue -
Modify
unsetAllMarkscommand in/tiptap/packages/core/src/commands/unsetAllMarks.tsto:- Accept an optional
{ ignoreClearable?: boolean }option - Check each mark's
clearableconfig before removing it - If
clearable: falseandignoreClearable: false, preserve the mark - For
can().unsetAllMarks(), returntruewhen the selection only contains non-clearable marks (successful no-op)
- Accept an optional
-
Update the module declaration to reflect the new interface
Now let me implement these changes:
-
Assistant
Now I need to add the
clearableproperty toMarkConfig. Let me add it after theexitableproperty:Assistant
Now I'll add the
clearableproperty toMarkConfigafter theexitableproperty (after line 62):Assistant
Let me verify the change:
Assistant
The
clearableproperty has been added. Now I need to update theunsetAllMarkscommand. Let me look at how to access the extension configuration from within the command:Assistant
Now I need to understand how to access the
clearableconfiguration for each mark. Let me look at how other commands access extension configurations:Assistant
Good. So I can access
editor.extensionManager.extensionsto get the list of extensions and check theclearableconfiguration. Let me look at one of these commands for reference:Assistant
Now I understand. I need to look at how to get mark configuration from the extension. Let me also check if there's a helper function to get extension config:
Assistant
Now I have all the information I need. Let me now rewrite the
unsetAllMarkscommand to:- Accept an optional
{ ignoreClearable?: boolean }parameter - Check each mark's
clearableconfig before removing - For
can()mode (whendispatchis undefined), returntruewhen selection only contains non-clearable marks (successful no-op)
- Accept an optional
Assistant
Now let me verify the file was created correctly:
Assistant
Now let me write a test script to verify the implementation works correctly:
Assistant
I need to continue exploring the project structure to understand how to run tests and verify my implementation. Let me check for test-related scripts and the package manager being used.
Assistant
Now let me run the unit tests to make sure I haven't broken anything:
Assistant
Let me try running just the tests related to the commands:
Assistant
The test timed out because pnpm needed to be installed. Let me check if pnpm is already available and try to run tests differently.
Assistant
Now let me check if node_modules exists and install dependencies if needed:
Assistant
Good, node_modules exists. Let me now try running the tests:
Assistant
The tests are running and passing. Let me wait for the full test run to complete to see if all tests pass:
Assistant
All 1064 tests passed! Now let me create a test script to verify my implementation works correctly for the specific requirements:
Assistant
The test script can't run directly because the TypeScript files need to be compiled first. Let me use vitest to run the test instead:
Assistant
Let me create a proper test file that can be run with vitest:
Assistant
Now let me run this test to verify my implementation:
Assistant
All 7 tests passed! Now let me clean up my test file since I shouldn't add tests to the repository:
Assistant
Now let me run the existing tests again to make sure my changes don't break anything:
Assistant
All 1064 tests still pass. Now let me also verify my changes look correct by reviewing the final state of the modified files:
Assistant
Let me verify the TypeScript compilation and make sure there are no type errors:
Assistant
Let me check the project structure for TypeScript configuration:
Assistant
The TypeScript errors are from the demos directory, not from the packages/core directory. These are pre-existing errors in the demo files, not related to my changes. Let me check if the core package compiles correctly:
Assistant
The errors are all in the demos directory, not in the packages/core directory. This is expected since the tsconfig includes the whole project. Let me check specifically for errors in the core package files:
Assistant
The errors in
transformPastedHTML.test.tsare pre-existing test file issues (unrelated to my changes). Let me verify there are no errors in the source files I modified (unsetAllMarks.tsandMark.ts).Assistant
There's a TypeScript error in my code. Let me look at line 79:
Assistant
The error is about the
dispatchcondition on line 79 - TypeScript thinks the condition will always be true. This is because the code flow already has an early return if!dispatch(line 53-77). After thatif (!dispatch)block returns, TypeScript knows thatdispatchmust be truthy, so checkingif (dispatch)will always be true.I should change the
if (dispatch)to just remove the condition, or useelse:Assistant
Now let me verify there are no more TypeScript errors:
Assistant
No more TypeScript errors related to my changes. Let me run the tests again to make sure everything still passes:
Assistant
All 1064 tests pass. Let me verify the final state of my changes:
Assistant
The changes look correct. Let me now summarize what I've done and verify the checklist:
Summary of Changes
1. Added
clearableoption to MarkConfig (packages/core/src/Mark.ts)- Added a new optional property that can be with default
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.