Untitled conversation
- User
[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.
- Assistant
I'll implement
MarkConfig.clearableand updateunsetAllMarksso comment marks survive clear-formatting. Exploring the codebase first. - Assistant
Implementing
MarkConfig.clearableand updatingunsetAllMarksto respect it. - Assistant
Implemented the
clearablemark configuration and updatedunsetAllMarksso semantic marks like comments can survive clear-formatting.Changes
-
MarkConfig.clearable(packages/core/src/Mark.ts)- New option:
boolean | (() => boolean), defaulttrue - Marks with
clearable: falseare preserved byunsetAllMarks()
- New option:
-
unsetAllMarkscommand (packages/core/src/commands/unsetAllMarks.ts)- Accepts optional
{ ignoreClearable?: boolean } - Removes only clearable marks by default
ignoreClearable: trueremoves all marks (previous behavior)can().unsetAllMarks()returnstruewhen the selection only has non-clearable marks (successful no-op)
- Accepts optional
-
isMarkClearablehelper (packages/core/src/helpers/isMarkClearable.ts)- Resolves the
clearableconfig per mark extension at runtime
- Resolves the
-
Tests (
packages/core/__tests__/unsetAllMarks.spec.ts)- Covers clearable/non-clearable marks,
ignoreClearable,can(), andunsetMarkstill working on non-clearable marks
- Covers clearable/non-clearable marks,
Usage
For the comments extension (not in this monorepo), set:
Mark.create({ name: 'comment', clearable: false, // ... })Then
editor.commands.unsetAllMarks()will remove bold, italic, link, etc., but keep comments. Your clear-formatting button can useunsetAllMarks()again instead of callingunsetMarkfor each formatting mark.Please review the changes and let me know if you'd like anything adjusted — for example, a changeset wording tweak or help wiring
clearable: falseintoextension-commentsif that package lives elsewhere. -
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
- composer-2.5Compare side by side →
- composer-2.5Compare side by side →
- composer-2.5Compare side by side →
- composer-2.5Compare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-solCompare side by side →
- fable-5Compare side by side →
- fable-5Compare side by side →