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.
Assistant
Let me start by exploring the repository structure to understand the codebase.
Assistant
Now I understand the issue. Let me check the extension-comments package to understand how it'sstructured:
Assistant
Now let me look at the existing test files for unsetAllMarks:
Assistant
Now let me look at the
can()command-related code to understand how commands handle thecancheck:Assistant
Now I understand the structure. The
can()function calls the command withdispatch: undefinedto check if the command would succeed. Let me look at how the can function returns true/false for unsetAllMarks:The unsetAllMarks command returns
truealways (when selection is not empty). The issue is that thecan().unsetAllMarks()should returntrueif the selection only has non-clearable marks (it'd be a no-op), and it should also returntrueif the selection has clearable marks. But the current implementation just returns true for any non-empty selection.Let me also explore how marks are defined and look at the
getMarkTypefunction to understand the data structures:Assistant
Now let me look at the structure of an existing mark to see how a mark is created:
Assistant
Let me look at the schema configuration for Bold to understand how marks are registered:
Assistant
Now I have a clear understanding. Let me look at how to access mark extensions from the schema/editor:
Assistant
Let me look at how splitExtensions works and how to get the mark extensions list:
Assistant
Now let me explore the structure of mark extensions and how to access them by name:
Assistant
Now let me look at how the
extensionsare accessed in the command:Assistant
Now let me look at the existing tests for unsetAllMarks:
Assistant
Let me check if there are tests or demos related to the unsetAllMarks:
Assistant
Let me create a script to reproduce the issue first:
Assistant
Now let me create a test script that reproduces the issue:
Assistant
Let me check how the existing tests are structured:
Assistant
Now let me create a test script to reproduce the bug:
Assistant
The test confirms the bug. Now let me implement the fix. First, let me modify the
Mark.tsto add theclearableconfig option:Assistant
Let me add the clearable property to MarkConfig.
Assistant
I duplicated the comment. Let me fix it:
Assistant
Now let me update the
unsetAllMarks.tscommand:Assistant
Now let me update the test to verify the fix works:
Assistant
The schema's
marksis not a Map. Let me check the actual structure:Assistant
The schema's
marksis an object. Let me fix the implementation:Assistant
All 5 tests pass! Let me also test the case where
clearableis a function:Assistant
Let me check the Extendable class to understand the
configobject better:Assistant
Let me look at the
resolveExtensionsandflattenExtensionshelpers:Assistant
Let me look at the Mark class to see how config is structured:
Assistant
Let me also make sure to consider edge cases. Let me also clean up the implementation a bit:
Assistant
Let me refactor the implementation to use the proper
Editortype:Assistant
Now let me run the tests again to make sure they still pass:
Assistant
All tests pass. Now let me also run the existing tests in the repository to make sure I didn't break anything:
Assistant
All 1072 existing tests pass. Now let me check for TypeScript compilation errors:
Assistant
Most of the TypeScript errors are in demos which are unrelated to my changes. Let me check specifically the core package:
Assistant
These errors are also in test files, not in my source code. Let me filter for source code errors:
Assistant
No TypeScript errors in the source code (only in pre-existing test files). Now let me remove my test file since the instructions say I shouldn't add tests:
Assistant
Now let me also check the docs to make sure the change is documented:
Assistant
Let me add a changeset for this feature:
Assistant
Now let me verify the final state of the changes:
Assistant
Now let me also create a test script to make a final verification (as a temporary script, will be removed before submission):
Assistant
The fix works. Let me also clean up the test file:
Assistant
Now let me run the entire test suite once more to make sure I didn't break anything:
Assistant
All 1064 tests pass. Let me also verify the current state of files:
Assistant
Let me also verify with a final comprehensive test that includes the demo setup:
Assistant
All comprehensive tests pass. Let me clean up:
Assistant
Now let me run the test suite one more time to confirm everything passes:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.