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 understanding the repository structure and then look at the specific files mentioned in the issue.
The issue is about
unsetAllMarksdeleting comments when it shouldn't. The solution involves:- Adding a
clearableoption toMarkConfig(defaulttrue) - Modifying
unsetAllMarkscommand to respect theclearableflag - Making
can().unsetAllMarks()returntruewhen the selection contains only non-clearable marks
Let me explore the repository structure first.
- Adding a
Assistant
Let me now look at the key files mentioned in the issue:
packages/core/src/Mark.ts- whereMarkConfigis definedpackages/core/src/commands/unsetAllMarks.ts- where theunsetAllMarkscommand is defined- The comments extension package
Let me explore these.
Assistant
I need to use a single command at a time.
Assistant
Let me now look at the relevant files.
Assistant
Let me look at the files one at a time
Assistant
Now let me look at Mark.ts.
Assistant
Now let me find the comments extension and also the types used.
Assistant
Nothing found. Let me search more broadly.
Assistant
The comments extension might be in a separate package. Let me look at the packages directory.
Assistant
Let me look at the Extendable class to understand config
Assistant
Let me check how the commands get their context and how marks are accessible
Assistant
Let me look at the
RawCommandstype and how commands access the editorAssistant
Let me look at the RawCommands type definition.
Assistant
Let me look at the Command type.
Assistant
Let me look at CommandProps.
Assistant
Let me look at how the Editor accesses extensions/marks.
Assistant
Let me look at ExtensionManager
Assistant
Let me look at how other commands interact with the editor and extensions
Assistant
Let me look at how to access the editor's extension manager to get mark configs
Assistant
Let me look at
callOrReturnand how the extension manager accesses mark configsAssistant
Let me look at the
getExtensionFieldhelperAssistant
Let me look at the Editor class to understand how to get extension by name
Assistant
Let me look at how extensionManager provides access to extensions
Assistant
Let me look at how to find an extension by name
Assistant
Let me look at existing tests for unsetAllMarks
Assistant
Let me search for tests
Assistant
Let me check the test structure and check existing tests for marks
Assistant
Let me check the test for delete.spec.ts to understand the test patterns
Assistant
Now I have a good understanding. Let me look at the
getMarkTypehelper and understand how to find an extension by name from the editorAssistant
Let me check if there's a helper to find extensions by name
Assistant
Let me check isList.ts for the pattern of finding extensions by name
Assistant
Let me check splitExtensions
Assistant
Now I have a thorough understanding. Let me implement the changes. First, let me add the
clearableproperty toMarkConfig.Assistant
Let me see the rest of the file
Assistant
Now let me add the
clearableproperty to theMarkConfiginterface. I'll add it afterexitable(line 62).Assistant
Good, the
clearableproperty has been added. Now let me modify theunsetAllMarkscommand.Assistant
Now let me rewrite the entire
unsetAllMarkscommand:Assistant
Now let me verify the changes compile and tests pass.
Assistant
Let me run the unit tests for the core package to check if changes break anything.
Assistant
Let me run from the root.
Assistant
All 1064 tests pass. Now let me write a quick reproduce script to verify the behavior:
unsetAllMarksremoves clearable marks but preserves non-clearable onesunsetAllMarks({ ignoreClearable: true })removes all markscan().unsetAllMarks()returnstrueeven on non-clearable marks
Assistant
Let me run this test script to verify the behavior
Assistant
Let me place the test file in the correct location.
Assistant
The test is missing vitest imports. Let me fix it
Assistant
Now let me run the test
Assistant
The 5 tests pass. The 2 failures are just test assertion issues — ProseMirror merges adjacent text nodes when they have the same marks. Let me fix the test
Assistant
Let me run the tests
Assistant
All 7 tests pass. Now let me clean up the test file (since the instructions say not to modify/add tests) and run the full test suite.
Assistant
Now run the full test suite.
Assistant
All 1064 tests pass. Let me also verify that the
clearabletype is properly exported from the package indexAssistant
Let me look at the core index.ts
Assistant
Not found. Let me check what's in the index.
Assistant
Let me do a final review of both changed
Assistant
Let me verify TypeScript compilation for the core package
Assistant
Let me find the tsconfig
Assistant
Let me try building the core package
Assistant
Build succeeds. Let me verify the
clearableproperty is in the generated type definitions
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.