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.jseditor.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 start by exploring the repository structure to understand the codebase.
Assistant
Now let me check the extension-comments to understand what we're dealing with.
Assistant
The extension-comments package isn't in this list, but the issue mentions it. Let me check if there are any tests related to this.
Assistant
Let me look at the package.json to understand the testing setup.
Assistant
Let me look at the can.spec.ts to understand how command tests are done.
Assistant
Now let me look at the unsetMark command to understand the context better.
Assistant
Now let me look at the structure of the Mark class and how to get a MarkType.
Assistant
Now let me look at the schema to understand mark structure.
Assistant
Now let me look at the existing extension-bold as an example to understand how the mark config options work:
Assistant
Let me look at how the can() function works:
Assistant
Now let me look at the structure of Mark - how it stores config:
Assistant
Let me look at how the schema is built:
Assistant
Let me look at how the mark spec is built and how we can add custom fields to it:
Assistant
Let me check
tr.removeMark:Assistant
Let me see how
splittableMarksis implemented (similar pattern):Assistant
Now I have a clear picture. Let me look at how editor is accessed in commands:
Assistant
Now let me look at thecallOrReturn helper:
Assistant
Now let me check how
editor.extensionManagerexposes the mark extensions:Assistant
Let me look at splitExtensions:
Assistant
Let me check the MarkSpec type:
Assistant
Let me look at how unsetAllMarks is referenced and used:
Assistant
Now let me first reproduce the bug:
Assistant
Let me first check if I can run the existing tests:
Assistant
Tests work. Let me create a temporary test to verify the current bug behavior:
Assistant
Let me create a temporary test file in the packages folder:
Assistant
I've reproduced the bug. The comment mark is removed along with the bold mark when
unsetAllMarksis called. Now let me implement the fix.Step 1: Add
clearableoption to MarkConfigAssistant
Now I'll add the
clearableoption right aftercode. Let me check the existing pattern forkeepOnSplitsince it's a similar boolean option:Assistant
Now let me add the
clearableoption aftercode:Assistant
The edit went wrong. Let me reset and try again:
Assistant
Let me reset and use a more careful approach with the replace command:
Assistant
Now let me verify the changes to Mark.ts:
Assistant
Step 2: Add
clearableto the mark schemaAssistant
Now I'll add
clearableto the mark schema:Assistant
Let me use the edit command with the correct file path:
Assistant
Now let me verify the
cleanUpSchemaItemfunction will not filter outundefinedvalues. Let me check:Assistant
Step 3: Update the
unsetAllMarkscommandAssistant
Now let me test the change with the temporary test:
Assistant
Let me check the schema API:
Assistant
schema.marksis an object{ [name]: MarkType }, not an iterable. Let me fix the command:Assistant
The test is still failing because the Comment mark in my test doesn't have
clearable: false. Let me update my test:Assistant
All 4 tests pass. Now let me run the full existing test suite to make sure I haven't broken anything:
Assistant
All 410 tests pass. Let me also run the tests for other packages to make sure nothing is broken:
Assistant
All 1064 tests pass across 117 test files. Now let me verify edge cases with more comprehensive tests:
Assistant
Let me investigate the
configureissue. Let me look at howconfigureworks:Assistant
The
configuremethod only updatesaddOptions, not top-level config fields likeclearable. This is the expected behavior. Let me remove those incorrect tests:Assistant
All 8 tests pass. Let me clean up the temporary test file:
Assistant
Let me think about edge cases that I might have missed:
- What if the mark extension uses
extend()to addclearable: falseto an existing clearable mark? - What about empty selection? - already tested.
- What if
clearablereturnsundefined?
Let me also look at the TypeScript types to make sure the types are correct:
- What if the mark extension uses
Assistant
All 5 edge case tests pass. Let me clean up:
Assistant
Let me verify the final diff of my changes:
Assistant
Let me also check the TypeScript compilation works:
Assistant
Let me filter to only check core packages, excluding unrelated demos errors:
Assistant
These errors are in test files that were already broken, not in my changes. Let me check just the files I modified:
Assistant
No errors in my changes! Let me also check the build:
Assistant
Build succeeded. Now let me check the generated types:
Assistant
The
clearableoption is exposed in the generated types. Let me run the test suite again to ensure my changes pass all existing tests:Assistant
All 410 tests pass. Let me also run the full test suite again:
Assistant
All 1064 tests pass. Let me verify the final diff is clean:
Assistant
Let me also check the git status to ensure I have everythingI need:
Assistant
Let me also check if I need to add a changeset:
Assistant
Let me create a changeset for the changes I made:
Assistant
Let me verify the final state of all changes:
Assistant
Wait, the changeset will be submitted, but I am unsure if I should add it. Let me check the contribution guidelinesto see if changesets are required:
Assistant
Let me run the test suite one more time and verify everything works:
Assistant
All 1064 tests pass. Let me reproduce the bug one more time to ensure my fix is correct:
Assistant
All 4 tests pass. Let me clean up the temporary test file:
Assistant
Let me verify the final state of all changes:
Assistant
The diff looks clean and minimal. Let me also verify the changeset:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.