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 check the
extension-commentspackage to see how the comment mark is implemented:Assistant
The
extension-commentspackage isn't in this repo. Let me look at the test files and find relevant existing patterns:Assistant
Let me look at how
extension-boldimplements its mark and similar options:Assistant
Let me look at the
Mark.tsmore carefully and understand how options are evaluated:Assistant
Let me look at
getExtensionFieldto understand howclearableshould be evaluated:Assistant
Now let me look at how
schema.markslooks like to understand the structure:Assistant
Let me look at how
extensionsare passed to commands (so I can find the mark extensions and their config):Assistant
Now I have a good understanding of the structure. Let me look at how
exitableis used, since it's a similar boolean config option:Assistant
Now let me look at how
keepOnSplitis used, which is similar:Assistant
Let me look at
getExtensionField<MarkConfig['exitable']>to understand the pattern:Assistant
Let me look at the
editor.extensionManager.extensions:Assistant
Let me check the
toggleList.tsfile as it uses theextensionManager.extensions:Assistant
Good - now I understand how to access extensions and their config. Let me look at the
removeMarkfunction from ProseMirror to understand:Assistant
Now let me explore the tests for commands in
core:Assistant
Let me look at the existing implementations of marks and how
keepOnSplitis configured:Assistant
Now let me check how
extension-codedefinesexitable:Assistant
Now I have a complete understanding. Let me set up a reproduction script. Let me first check the existing build setup:
Assistant
Let me first run the existing tests for
coreto make sure they pass before I make changes:Assistant
All existing tests pass. Now let me write a reproduction script:
Assistant
Let me create a reproduction script to confirm the issue:
Assistant
Let me write a vitest-style test to verify the behavior, since the codebase uses vitest:
Assistant
Let me fix the test to use proper setup with the comment containing the bold mark (as described in the original issue):
Assistant
I've successfully reproduced the bug. Now let me look at how the
isActivehelper works for marks:Assistant
Now I have a clear picture. Let me implement the fix.
Step 1: Add
clearabletoMarkConfigAssistant
Now let me modify
Mark.tsto add theclearableoption:Assistant
I made a mistake with the sed. Let me revert and apply the change correctly:
Assistant
Now let me use
editinstead:Assistant
Let me use Python to do the substitution precisely:
Assistant
Step 2: Modify the
unsetAllMarkscommandAssistant
Let me test the change:
Assistant
I'm passing the extension instance instead of the MarkType. Let me fix this by getting the actual MarkType:
Assistant
Now let me update my reproduction script to also test the new functionality:
Assistant
All my reproduction and fix tests pass. Now let me run all existing tests to make sure I didn't break anything:
Assistant
All 384 tests pass. Let me also run tests for related packages that use marks:
Assistant
Let me also run the tests for all packages in
packages/to make sure nothing is broken:Assistant
Let me also think about edge cases and verify:
Assistant
Let me check the issue. The code mark has
excludes: '_'which excludes all other marks. Let me investigate:Assistant
I see -
codehasexcludes: '_'which excludes all other marks. Let me update my test to remove that combination:Assistant
All tests pass. Now let me clean up the temporary test files I created:
Assistant
Now let me also clean up other temporary files:
Assistant
Let me look at my final implementation once more:
Assistant
Let me look at CommandProps to ensure state is available:
Assistant
Good -
stateis available in CommandProps. Let me also check if there are any issues withgetExtensionFieldwhen the mark extension doesn't haveclearableset:Assistant
Let me also verify the
getExtensionFieldbehavior for missingclearablefield:Assistant
Now let me run the full test suite once more to make sure I didn't break anything:
Assistant
All 377 existing tests pass.
Let me also test a few edge cases I might have missed - the
chain().unsetAllMarks()command:Assistant
All tests pass. Let me run the full test suite once more to be safe:
Assistant
All 1064 tests pass. Let me also check the
extension-commentspackage is somewhere. Actually let me search theextension-commentslocation more broadly:Assistant
Let me check if there are any changesets related to this issue or whether I should add one:
Assistant
Let me add a changeset for this fix:
Assistant
Now let me verify the final implementation:
Assistant
Let me also check if there are any TypeScript issues:
Assistant
Let me check if there are any TS errors specific to my changes:
Assistant
Let me fix this TS error:
Assistant
Let me check how other commands handle this:
Assistant
The Storage is exported from index.ts, not types.ts. Let me check where ExtensionManager.ts imports it from:
Assistant
Storage is imported from
./index.js, not./types.js. Let me fix my import:Assistant
No more TS errors related to my changes. Let me run the full test suite once more:
Assistant
All 377 tests pass. Let me also write a final reproduction script to confirm the original issue is fixed:
Assistant
All my tests pass and the original issue is fixed. Let me check the final state of the implementation:
Assistant
Let me also check if there's a
callOrReturnre-exported from@tiptap/core(so I don't need a separate import):Assistant
Let me run the full test suite one more time to confirm everything works:
Assistant
All 1064 tests pass. Let me also check the
.changesetfile:Assistant
Let me also check if there are any lint issues:
Assistant
No lint errors. Let me also check the formatting:
Assistant
Let me see the format issues:
Assistant
Good, oxfmt just made minor formatting changes. Let me run the tests again to confirm everything still works:
Assistant
All formatting checks pass. Let me also run all tests once more:
Assistant
All 1064 tests pass. Let me show the final diff:
Assistant
The implementation is complete. Let me also verify my changes one more time by running all tests once more:
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 →