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 work on implementing the solution described in the issue.
The issue describes:
unsetAllMarksdeletes comments (which are marks)- The solution: Add a
clearableoption toMarkConfigthat defaults totrue, but when set tofalse, the mark survivesunsetAllMarks() unsetAllMarksshould accept anoptions?: { ignoreClearable?: boolean }parametercan().unsetAllMarks()should returntruewhen selection contains only non-clearable marks
Let me explore the repository structure first.
Assistant
Let me explore the key files mentioned in the issue
Assistant
I need to make one command at a time.
Assistant
Let me look at the key files: Mark.ts and the commands directory.
Assistant
Now let me look at the unsetAllMarks command and the comments extension:
Assistant
Let's look at unsetAllMarks.ts and the comments extension.
Assistant
Now let me find the comments extension and check how marks are processed
Assistant
No results for comment. Let me try a different search.
Assistant
Let me look at how the marks are structured and check for tests.
Assistant
Let me look at the types file to understand the command types.
Assistant
Let me find the RawCommands type definition:
Assistant
Let me look at the RawCommands type definition in types.ts around line 851:
Assistant
Let me look at the UnionCommands type to find unsetAllMarks
Assistant
Let me look at the Commands type which provides the actual command signatures:
Assistant
Let me search more broadly:
Assistant
Let me look at the Extendable.ts for understanding how marks are configured
Assistant
Let me look at the index.ts to see what's exported:
Assistant
Let me look at the unsetMark command for reference:
Assistant
Let me check how existing marks are structured, for example, the bold mark
Assistant
Let me find the correct path for extension-bold
Assistant
Let me look at the bold extension and its test:
Assistant
The file is bold.jsx, not bold.ts. Let me check:
Assistant
OK, let me look at the bold extension to understand the pattern:
Assistant
Let me understand how the Mark config is transferred to the schema. Let me look at the ExtensionManager:
Assistant
Let me look at how the Mark schema is generated:
Assistant
Let me look at the full getSchemaByResolvedExtensions.ts to understand how marks are set up:
Assistant
Now I have a good understanding. Let me create a plan and implement the changes:
Mark.ts: Addclearableoption toMarkConfig(defaulttrue)getSchemaByResolvedExtensions.ts: Includeclearablein the mark's ProseMirror specunsetAllMarks.ts: Modify to respectclearable, accept{ ignoreClearable?: boolean }option
Let me first check the test files for unsetAllMarks:
Assistant
Now let me implement the changes. I'll start with
Mark.tsto add theclearableoption.Assistant
Let me open it with the open command correctly:
Assistant
Let me see the rest of the MarkConfig interface:
Assistant
Now let me add the
clearableoption toMarkConfig. I'll add it after `keepOnSplitAssistant
Let me use the proper syntax for multi-line edit:
Assistant
Let me try the proper syntax:
Assistant
I need to add a blank line before the clearable comment for proper spacing. Let me fix that
Assistant
I need to add a blank line between the
clearablefield and theinclusivecomment. Let me fix:Assistant
Let me use replace to fix the spacing properly
Assistant
Good. Now let me update
getSchemaByResolvedExtensions.tsto include theclearablein the mark's ProseMirror spec.Assistant
Let me try to open this file:
Assistant
Let me scroll to the marks section (around line 160):
Assistant
Now I need to add
clearableto the mark schema. Let me edit it:Assistant
The
??operator is causing issues. Let me use a different approach:Assistant
Now let me update the
unsetAllMarks.tscommand to respect theclearableoption:Assistant
Let me try opening with the open command
Assistant
Now let me rewrite the unsetAllMarks command:
Assistant
Let me check if the MarkSpec type from ProseMirror supports arbitrary properties, and what types we're working with:
Assistant
Let me find the pm package:
Assistant
Let me check the pm package for MarkSpec types:
Assistant
Let me look at the model's type exports to see if MarkSpec includes arbitrary properties:
Assistant
Let me check the prosemirror-model types:
Assistant
Let me find the prosemirror-model package:
Assistant
Let me check the MarkSpec type definition:
Assistant
Let me check the MarkSpec interface:
Assistant
Let me see the rest of MarkSpec:
Assistant
Good.
MarkSpechas[key: string]: any;somarkType.spec.clearablewill work. Now let me run the existing tests to verify nothing is broken:Assistant
All 410 tests pass. Let me now create a quick test to verify the new functionality works:
Assistant
Now let me run this test:
Assistant
Let me move the test to the repo root:
Assistant
Let me run the test:
Assistant
The fix is working! The non-clearable mark survived. The error is just a test issue - after removing the clearable mark, the two adjacent text nodes with identical marks got merged into one. Let me fix the test:
Assistant
Let me run the test:
Assistant
All 4 test scenarios pass. Let me clean up the temporary test file and run the full test suite one final time:
Assistant
All 410 tests pass. Let me verify the final state of all modified files:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.