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.
Type: Command Name: unsetAllMarks Path: packages/core/src/commands/unsetAllMarks.ts Input: options?: { ignoreClearable?: boolean } Output: ReturnType Description: Removes clearable marks from the current selection. Marks configured with clearable: false are preserved unless ignoreClearable is true. can().unsetAllMarks() returns true when the selection contains only non-clearable marks; this case is a successful no-op.
ADDITIONAL ADVICE
Since you are given a git repository, you can use git commands to simplify your work. For example, if you made a mistake and want to revert your changes, you can use
git checkout <file>to restore the file to its original state. You can also reset all changes in the repository usinggit reset --hardcommand. Additionally, you can usegit stashandgit stash popto temporarily save your changes and restore them later. Finally, you can see the changes that you've made (which will be submitted when you callsubmit) usinggit statusorgit diffcommands. However you don't need to usegit addorgit commitbefore submitting your changes. In fact,submitonly submits currently unstaged changes because it usesgit diffto get the changes that need to be submitted.CHECKLIST
Before submitting your solution, please go over the following checklist and make sure you've done everything:
- If an error was reported in the issue description, I have successfully reproduced it.
- If an error was reported in the issue description, I have confirmed that my fix resolves the error.
- I have thought about edge cases and made sure my fix handles them as well.
- I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass. I want you to list every bullet from this checklist and write your reasoning for why you think you did it or didn't need to.
Repository has been uploaded and your shell is currently at the repository root. Time to solve the issue!
(Current directory: /tiptap, current file: none) bash-$
Assistant
Let me start by exploring the repository structure to understand the codebase.
Assistant
Now let me look at the extension-comments package to understandthe existing comment mark.
Assistant
The extension-comments doesn't exist in the repo yet. Let me look at the unsetMark command too.
Assistant
There's no test for unsetAllMarks currently. Let me look at the can.ts file to understand the
can()method.Assistant
Now let me look at how tests are structured for similar commands:
Assistant
No existing "clearable" property. Now let me look at the ExtensionManager.ts to understand how marks are accessed incommands:
Assistant
Let me look at how to access marks via the schema:
Assistant
Let me look at how the existing
unsetMark.tsaccesses marks:Assistant
Let me look at how thetoggleList command uses the extension manager to understand more:
Assistant
Now I have a clear understanding. Let me look at the callOrReturn utility:
Assistant
Now let me understand what tests look like in the project:
Assistant
Let me check the test configuration file:
Assistant
Let me look at the existing tests for unsetMark to understand how it is tested:
Assistant
Now I have a good understanding of the codebase. Let me look at what other mark configurations look like:
Assistant
Now let me look at how the existing tests for marks look like:
Assistant
Now let me check how
extensionManagerexposes marks:Assistant
Let me see how splitExtensions is exposed for the editor:
Assistant
Now let me check the schema to see what marks we have:
Assistant
Let me look at how the
getMarksBetweenhelper works, it might be useful:Assistant
Now let me look at the structure of how to get the mark extensions from the extension manager:
Assistant
Now let me understand how to access
editor.schemaandeditor.extensionManager:Assistant
Now I have a clear plan. Let me first look at the current changesets directory to understand the format:
Assistant
Now let me look at how
editor.schemaandeditor.extensionManagerare used:Assistant
Good. Now I have enough information to make the changes. Let me now implement the
clearableoption inMarkConfig:Assistant
Now let me add the
clearableoption to the MarkConfig:Assistant
Let me make the edit to add the
clearableoption to MarkConfig.Assistant
I see there's a duplicate line. Let me fix that.
Assistant
The edit didn't quite work as expected. Let me undo and try again.
Assistant
Now let me redo the edit with a clearer replacement:
Assistant
Let me try a different approach using
replace:Assistant
Now the file looks correct. Let me verify the diff:
Assistant
Now let me update the
unsetAllMarkscommand:Assistant
Now let me check what the
Markinstance properties look like to accessclearable:Assistant
Let me see how to access the editor instance from a command, since I need the extensions:
Assistant
Now I understand. Let me also look at how to get a mark extension's
clearableproperty usingcallOrReturnand thegetExtensionField:Assistant
Let me look at how the
splitExtensionsworks:Assistant
Now let me look at how
dispatchis used incommandManager:Assistant
Good. So when
can()is called,dispatchis undefined. Let me now write the new unsetAllMarks command:Assistant
Let me write a script to test my implementation.
Assistant
Let me run the test using vitest with my test file:
Assistant
Let me create a vitest test file to test my implementation:
Assistant
Let me debug by adding logging to understand the test failures:
Assistant
Let me debug further with selectAll:
Assistant
My implementation is working correctly! Let me fix the test file:
Assistant
All 8 tests pass. Now let me clean up by removing the temp test files and verify the existing tests still pass:
Assistant
Let me verify the test files are removed:
Assistant
Let me run the existing tests to make sure I didn't break anything:
Assistant
All 377 tests pass. Now let me also check the
__tests__folder insidesrc:Assistant
Let me also run a broader test to make sure I haven't broken anything:
Assistant
Now let me verify the implementation more carefully. Let me re-read my implementation:
Assistant
Let me also run all tests to make sure I haven't broken anything:
Assistant
All 1064 tests pass. Now let me also look at the markdown package which might also have similar functionality:
Assistant
Let me also add a changeset for this change:
Assistant
Let me check if there's any other place where
unsetAllMarksis used:Assistant
Let me also run the linter to check formatting:
Assistant
Let me now run all tests one more time to make sure I haven't broken anything:
Assistant
All 410 tests pass. Let me also verify the changes I made look correct:
Assistant
Let me verify that the test files I created earlier have been removed:
Assistant
Let me also verify the final version of my changes:
Assistant
Let me also run all the tests one more time to verify everything passes:
Assistant
All 1064 tests pass. Let me also verify by trying to build the core package:
Assistant
Build is successful. Let me also clean up the dist directory to avoid including it in the submission:
Assistant
Let me also check that the build was successful and the distdirectory is gone:
Assistant
Let me also verify the final diff one more time:
Assistant
Let me do one final sanity check by running all the tests:
Assistant
All 410 tests in
packages/corepass. Let me now also write a temporary test script to validate the contract one more time:Assistant
The validation script ran and all 4 tests PASSED. The vitest error is just because the file doesn't contain a
describeoritblock - it's just a script. Let me clean it up:Assistant
All checks pass. Let me go through the final checklist:
Checklist Verification:
-
If an error was reported in the issue description, I have successfully reproduced it.
- I created temporary test scripts that reproduced the bug: calling
unsetAllMarkswould remove all marks including comment marks.
- I created temporary test scripts that reproduced the bug: calling
-
If an error was reported in the issue description, I have confirmed that my fix resolves the error.
- My fix adds a
clearableoption toMarkConfig(defaulttrue). Whenclearable: falseis set, the mark is preserved byunsetAllMarks(). My test script confirmed:- Marks with
clearable: falseare preserved byunsetAllMarks() unsetAllMarks({ ignoreClearable: true })removes themcan().unsetAllMarks()returnstrueeven for non-clearable marks only- Explicit
unsetMarkstill works (removes the mark regardless ofclearable)
- Marks with
- My fix adds a
-
I have thought about edge cases and made sure my fix handles them as well.
- Empty selection: returns true (no-op)
- Selection with mixed clearable/non-clearable marks: only clearable marks are removed
- Selection with only non-clearable marks: no marks are removed, returns true (successful no-op)
ignoreClearable: true: all marks are removedclearableas function: handled viacallOrReturn- Marks without matching extension: treated as clearable (default)
- Mark extension with parent (wrapped):
getExtensionFieldwalks up parent chain
-
I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass.
- All 1064 existing tests in
packages/pass - All 410 tests in
packages/core/pass
- All 1064 existing tests in
Now let me submit my changes:
-
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Identical first prompt
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →