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
Good,
editoris available. Now let's addclearablefield to Mark.ts and implement the command using ExtensionManager extensions to find non-clearable mark names.Assistant
Now I'll add the
clearablefield afterkeepOnSplit(line 31) or nearexitable. Let's add afterexitable.Assistant
Now let's check where
Mark.configstatic defaults might set defaults forexitable/keepOnSplit, to add default forclearable.Assistant
Now let's write the updated
unsetAllMarks.ts.Assistant
Let's fix storage to use
editor.extensionStorage[extension.name]for consistency with ExtensionManager pattern.Assistant
Pre-existing unrelated errors. Good, no new errors from our files. Now let's check the pro extension-comments package to see if it should set
clearable: falseon its Comment mark.Assistant
No existing test file. Let's check tests dir structure for commands tests, and also check the CHANGELOG to see typical practice.
Assistant
Now let's write a temp script (not a test file in the repo test folder) to verify behavior using vitest run inline, or just write a quick node script with vitest. Let's create a temp spec outside tests and run vitest on it directly, then delete it before submitting.
Assistant
All tests pass. Now let's remove the temp test file and run the full core test suite to check nothing broke.
Assistant
All 410 tests pass. Now let's also check
can.spec.tsfor existing unsetAllMarks tests and check the CHANGELOG convention for adding changeset.Assistant
Let's add a changeset for this change.
Assistant
Now let's double check the docs for unsetAllMarks command, if exists, to update documentation too.
Assistant
No docs folder in this repo (docs likely live in a separate repo). Now let's review the final diff.
Assistant
This looks solid. Let's also verify
unsetAllMarksis used elsewhere in the codebase (e.g., in other packages) that might need updates for the new signature.Assistant
That's just my comment. Good, no other usages need updates. Now let's run lint to check code style conformance.
Assistant
Lint passes. Now let's run format check to ensure consistent style.
Assistant
Formatting is correct. Now let's do a final full test run for the whole repo (or at least core + related packages) to make sure nothing else broke.
Assistant
All 1064 tests pass across the whole repo. Let's clean up the temp reproduce file if still present anywhere.
Assistant
Clean diff, no stray test files. Let's review the final files once more.
Assistant
This implementation satisfies the interface contract described in the issue. Now let's go through the checklist.
Assistant
Let's briefly verify the fix actually addresses the original bug by testing against the old implementation (to confirm regression test would catch it).
Assistant
This confirms the bug reproduces before the fix. Now restore the fix and remove the temp test.
Assistant
Now let's re-run the full test to confirm the fix works and nothing is broken after popping stash.
Assistant
All good. Now let's finalize checklist review before submitting.
Checklist Review
-
If an error was reported in the issue description, I have successfully reproduced it. ✅ I wrote a temporary test (
zzz_check.spec.ts) using aComment-like mark configured withclearable: false, appliedunsetAllMarks()against the original, unmodified code (bygit stash-ing my fix), and confirmed the mark was deleted — exactly matching the reported bug where comment-wrapping marks got stripped by "clear formatting". The temp file was removed afterward and is not part of the submitted diff. -
If an error was reported in the issue description, I have confirmed that my fix resolves the error. ✅ After restoring my fix (
git stash pop), I re-ran an equivalent test suite (zzz_reproduce.spec.ts, later deleted) covering: (1) default behavior preserves aclearable: falsemark onunsetAllMarks(), (2)unsetAllMarks({ ignoreClearable: true })removes it, (3)editor.can().unsetAllMarks()returnstrue(no-op) when only non-clearable marks are present, and (4) explicitunsetMark('comment')still removes the non-clearable mark. All four passed. -
I have thought about edge cases and made sure my fix handles them as well. ✅ Considered: empty selection (early return unaffected), multiple ranges, marks with a function-valued
clearable(handled viacallOrReturn), mixing clearable and non-clearable marks in the same selection (loop skips only non-clearable types viatr.removeMark(from, to, markType)), and thecan()dry-run path (command always returnstrue, satisfying the "no-op success" contract).
-
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 →
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 →