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
I'll start by exploring the repository structure to understand the codebase. Let me first see what's in the root directory.
- Assistant
Let me look at the repository structure more carefully and understand the packages.
- Assistant
I don't see an
extension-commentspackage. Let me check for theextension-commentsand also look at the core package structure. - Assistant
No comments extension found. Let me look at the relevant files mentioned in the issue - the core Mark.ts and the unsetAllMarks command.
- Assistant
Let me look at the core files: Mark.ts and unsetAllMarks.ts
- Assistant
Now let me look at the Mark.ts file in core to understand how marks are configured.
- Assistant
Let me check the tests directory and see how the issue manifests. I need to understand the evaluation contract:
MarkConfig.clearable- Mark configuration option with defaulttrueunsetAllMarkscommand needs to accept{ ignoreClearable?: boolean }option- Marks with
clearable: falsemust surviveunsetAllMarks()unlessignoreClearable: true can().unsetAllMarks()returns true when selection contains only non-clearable marks (successful no-op)
Let me look at the existing test files to understand how tests are structured:
- Assistant
Let me look at how marks are typically configured in extensions:
- Assistant
Let me check the bold extension directory structure.
- Assistant
Let me examine the bold extension and some existing commands to understand the patterns used.
- Assistant
Let me look at the Extendable class to understand how marks are configured:
- Assistant
Let me now understand how
commandsandcan()work in the context of this editor: - Assistant
Let me look at how
CommandManagerimplementscan(): - Assistant
Let me check how
removeMarkworks in ProseMirror and also look at how marks are removed individually: - Assistant
Now let me understand how to access mark types in the schema and check if a mark is clearable:
- Assistant
Let me examine the types and understand how to access mark type properties:
- Assistant
Let me look at the extension manager and see how extensions and marks are stored:
- Assistant
Let me look at how to access mark types in the command context:
- Assistant
Let me look at how
callOrReturnis used to resolve boolean or function values: - Assistant
Now I understand the structure. Let me check how to get all mark types from the schema:
- Assistant
Let me look at how extensions are accessed in commands:
- Assistant
Let me look at the
unsetMarkcommand to understand how it works with mark types: - Assistant
Let me understand how to access mark extensions and their configs from within commands:
- Assistant
Now I have a clear understanding of the codebase. Let me implement the solution step by step.
First, let me add the
clearableproperty to MarkConfig in Mark.ts: - Assistant
Let me add the
clearableproperty to MarkConfig, afterexitable. Let me see more of the file. - Assistant
Now let me add the
clearableproperty to MarkConfig. I'll add it after theexitableproperty: - Assistant
Let me use the correct edit syntax:
- Assistant
Let me add the
clearableproperty afterexitable. I need to use the correct edit syntax. - Assistant
Good, the
clearableproperty has been added. Now I need to modify theunsetAllMarkscommand to:- Accept an optional
{ ignoreClearable?: boolean }parameter - Only remove marks that are "clearable" (i.e.,
clearableis true, which is the default) - If
ignoreClearableis true, remove all marks (current behavior)
Let me first understand how to access the editor's extensions and mark configs from within a command:
- Accept an optional
- Assistant
Let me look at the
splitExtensionshelper and see how extensions are split into nodes, marks, etc.: - Assistant
Now I need to understand how to get the mark extension's clearable property. Let me look at how to access extensions from within a command:
- Assistant
Let me search more broadly for how extensions are accessed.
- Assistant
Let me look at how the mark extensions' configs can be accessed:
- Assistant
Let me look at how marks are accessed from the document in a range:
- Assistant
Now let me look at the ExtensionManager more fully to understand how to access mark extensions:
- Assistant
Let me look at how
keepOnSplitis used, since it's similar toclearable: - Assistant
Now I understand how to access extension fields. Let me now implement the
unsetAllMarkscommand with the new logic. I need to:- Get all unique mark types in the selection ranges
- For each mark type, find the corresponding extension and check its
clearableproperty - Only remove clearable marks (unless
ignoreClearableis true)
Let me now update the
unsetAllMarks.tsfile: - Assistant
Now I'll update the
unsetAllMarkscommand to support theclearableproperty: - Assistant
Now let me verify that the code compiles correctly. First, let me check if there are any TypeScript issues:
- Assistant
Let me check if there are any errors specific to our changes:
- Assistant
Let me try with the full path
- Assistant
Let me check the tsconfig.
- Assistant
Let me look at the types setup more carefully. I see the
extensionStorageaccess might be incorrect. Let me fix it: - Assistant
Let me simplify the implementation. The context can be simplified since
clearableis a simpleboolean | (() => boolean)type. Let me also check howeditor.extensionStorageis accessed: - Assistant
Let me simplify the implementation to use
editor.extensionStoragedirectly: - Assistant
Now let me check the
CommandPropstype to make sureeditoris available: - Assistant
Let me check the types more carefully to make sure the command receives
editor. - Assistant
Good,
editoris available inCommandProps. Now let me check if there are existing tests forunsetAllMarks: - Assistant
Let me search differently:
- Assistant
No existing tests for
unsetAllMarks. Let me check what test framework is used: - Assistant
Let me look at the existing tests to understand the testing patterns:
- Assistant
Let me run the existing tests to make sure they pass before making any changes. First let me check how to run tests:
- Assistant
Let me run only the core tests.
- Assistant
All 410 tests passed. Now let me also verify the exports. Let me check if the Mark class and related types are properly exported:
- Assistant
Let me check how the exports work:
- Assistant
Let me check the index.ts file:
- Assistant
Let me verify that the
splitExtensionsfunction is exported from the helpers: - Assistant
Good. Now let me also check if
getExtensionFieldis exported: - Assistant
Good. Now let me write a temporary test script to verify the behavior works correctly:
- Assistant
Let me create a temporary test script to verify the behavior works correctly:
- Assistant
Let me run the test script using vitest:
- Assistant
Let me create a proper test spec file in the test directory:
- Assistant
Now let me run the test spec to see if the behavior is correct:
- Assistant
Let me analyze the failures. First, the content is not being parsed correctly. Let me debug:
- Assistant
Let me run the updated tests.
- Assistant
Looking at the output, it seems like nothing is being removed. Let me debug by adding console.log:
- Assistant
I see the issue. Looking at the debug output, the clearable values are correctly resolved, but the marks aren't being removed. Let me check what's happening. The issue might be with how the selection range interacts with marks. Let me simplify the approach - instead of scanning document nodes, let's just iterate over all mark types from the schema:
- Assistant
Let me add some debugging to the actual command:
- Assistant
Now let me run the tests again:
- Assistant
All 8 tests pass now. The implementation is working correctly. Let me clean up the temporary test file and make sure the existing tests still pass:
- Assistant
Now let me run all existing tests to make sure nothing is broken:
- Assistant
All 410 tests pass. Let me also check if there are any other tests that might be affected:
- Assistant
Good - no other tests reference unsetAllMarks. Let me also check if there's a comments extension that already sets
clearable: false. Let me also check what the tests look like forunsetMark: - Assistant
Let me do a final review of all my changes:
- Assistant
The diff looks clean and correct. Let me also verify the final state of the files:
- Assistant
Let me now run the full test suite one more time to make sure everything is working correctly:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.