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 analyze the issue:
- The issue is about
unsetAllMarkscommand deleting comments when it shouldn't - The solution involves adding a
clearableconfiguration option to marks - Marks with
clearable: falseshould surviveunsetAllMarks()operations - The
unsetAllMarkscommand should respect thisclearableoption
Let me start by exploring the repository structure to understand the codebase.
- The issue is about
Assistant
I need to explore the repository structure to understand how it's organized, particularly looking at the core package where the Mark configuration and unsetAllMarks command should be.
Assistant
Good, let me look at the relevant files - Mark.ts and unsetAllMarks.ts
Assistant
Now let me look at the unsetAllMarks command:
Assistant
Now let me look at the types file to understand the Commands interface better, and also check for existing tests:
Assistant
Let me look at the types.ts and unsetMark.ts for reference:
Assistant
Let me check for existing tests related to unsetAllMarks and how marks are tested:
Assistant
Let me continue looking at the types.ts file to find the Commands interface definition, particularly for unsetAllMarks and can().unsetAllMarks():
Assistant
Let me search for the Commands interface more broadly:
Assistant
Let me look for existing tests related to marks:
Assistant
Let me look for any existing tests related to unsetAllMarks specifically, and also look at the can() method implementation to understand how it works.
Assistant
Let me look at the can.spec.ts to understand how the can() method works.
Assistant
Let me look at how marks work and how to get mark configurations:
Assistant
Good - the
clearableproperty doesn't exist yet, so I need to implement it from scratch. Let me understand how marks store their configuration:Assistant
Let me look at how marks are created and how to access their configuration:
Assistant
I need to understand how ProseMirror mark types work. Let me look at the
setMark.tscommand to understand how marks are set and how I can access mark configuration.Assistant
Let me look at how marks are defined in the core to understand how configuration is stored:
Assistant
Let me look at the Extendable class:
Assistant
Let me look at an existing mark extension to understand the pattern:
Assistant
Let me look for the bold extension.
Assistant
Let me explore the repository structure better.
Assistant
Let me look at how the extension package handles marks and also look at how ProseMirror schema stores mark specs:
Assistant
Now let me look at how the comment extension is structured and find how ProseMirror mark types access spec/attributes:
Assistant
Let me explore the ProseMirror mark spec and how mark configuration is stored:
Assistant
Let me look at how the editor and command manager handle marks:
Assistant
Let me look at how marks are configured in the schema and how the Mark class builds the schema:
Assistant
Let me understand how mark spec is built from the Mark configuration:
Assistant
Let me look at how the Mark configuration is processed and how ProseMirror mark types store the configuration. I need to find where the mark spec is built.
Assistant
Now I need to understand how marks are created and how their configuration is accessible. I need to look at how the ProseMirror mark spec is built.
Let me search for where the mark spec is built from the Mark configuration.
Assistant
Let me understand the full approach. The
clearableproperty is a mark configuration option. When a mark is created, it has configuration that we can access through the mark type. Let me look at how ProseMirror mark types store their spec:In ProseMirror,
MarkType.speccontains the mark specification. So when we have aMarkType, we can accessmarkType.specto get the mark's configuration.The tiptap Mark class extends Extendable, and the configuration is stored in
this.config. The mark type in ProseMirror (MarkType) has aspecproperty that contains the mark specification.Let me check how tiptap stores the
clearableconfig in the spec.Looking at the issue description more carefully:
- The
clearableoption should be aboolean | (() => boolean)onMarkConfig - Default should be
true - In
unsetAllMarks, we need to check if each mark in the selection is clearable before removing it
- The
Assistant
Let me find how the schema is built.
Assistant
Now I need to look at how the schema is built to understand where the mark spec is created.
Assistant
Now I understand the architecture. Let me implement the solution step by step:
- Add
clearabletoMarkConfiginterface inMark.ts - Add
clearableto the mark schema ingetSchemaByResolvedExtensions.ts - Modify
unsetAllMarkscommand to respect theclearableoption
Let me start:
- Add
Assistant
Now I have a clear understanding of the codebase. Let me implement the solution step by step.
Step 1: Add
clearabletoMarkConfiginterface inMark.tsAssistant
Let me use sed instead.
Assistant
I'll use node.js for scripting instead of Python.
<tool_call> <function=bash_terminal> <parameter=command> node -e " const fs = require('fs'); const content = fs.readFileSync('/tiptap/packages/core/src/Mark.ts', 'r');
const search_text = ` /**
- Excludes */ excludes?: | MarkSpec['excludes'] | ((this: { name: string options: Options storage: Storage parent: ParentConfig<MarkConfig<Options, Storage>>['excludes'] editor?: Editor }) => MarkSpec['excludes'])`;
const replace_text = ` /**
- Excludes */ excludes?: | MarkSpec['excludes'] | ((this: { name: string options: Options storage: Storage parent: ParentConfig<MarkConfig<Options, Storage>>['excludes'] editor?: Editor }) => MarkSpec['excludes'])
/**
- Controls whether unsetAllMarks removes this mark.
- Set false for semantic marks such as comments that must survive clear-formatting operations.
- @default true */ clearable?: boolean | (() => boolean)`;
const newContent = content.replace(search_text, replace_text); fs.writeFileSync('/tiptap/packages/core/src/Mark.ts', newContent); console.log('Mark.ts updated'); " </tool_call>
Assistant
Let me use the bash_terminal tool correctly.
Assistant
The backticks inside the template literal are causing issues. Let me escape them properly.
Assistant
Now let me verify the change was applied correctly:
Assistant
Now let me update the schema building to include the
clearableproperty:Assistant
Now let me verify the change was applied correctly:
Assistant
Now I need to update the
unsetAllMarkscommand to respect theclearableproperty. Let me update it:Assistant
Now let me rewrite the
unsetAllMarkscommand:Assistant
Let me verify the new content:
Assistant
Let me reconsider the implementation. There's an issue with the current approach - when iterating with
nodesBetween, we might process overlapping node ranges incorrectly. Let me refine the implementation:Assistant
Let me verify the new content and also think about the logic more carefully. The implementation needs to:
- Find all marks in the selection
- Determine which marks are clearable
- Remove only the clearable marks
- Preserve non-clearable marks
The key insight is that when using
tr.removeMark(from, to, markType), it removes a specific mark type in the range. If I want to remove only specific marks (like bold) but keep others (like comments), I need to callremoveMarkfor each clearable mark type.Let me verify the implementation and make sure it's correct.
Assistant
Let me remove the unused import and run the tests:
Assistant
Now let me verify the tests exist and try to run them:
Assistant
I notice there's an unused variable
nonClearableMarksin the type. Let me clean that up:Assistant
Let me think about this more carefully and rewrite the implementation:
Assistant
Let me verify the file looks correct:
Assistant
I realize my implementation has a potential issue with overlapping node iteration. Let me simplify the approach - ProseMirror's
tr.removeMark(pos, to, markType)will only remove marks of that specific type, so I can just iterate over each clearable mark type and remove it from the selection range.Assistant
Let me verify the simplified implementation:
Assistant
Now let me run the tests to verify the changes work correctly:
Assistant
The build is in progress. Let me wait for it to complete.
Assistant
The build succeeded. The test command failed because vitest doesn't use
--filter. Let me run the tests directly:Assistant
Let me check how tests are run in this repository.
Assistant
Let me find how to run tests in this repository.
Assistant
Let me run the unit tests to verify the changes work correctly.
Assistant
All 1064 tests passed. Now let me create a test script to verify the fix specifically for the
unsetAllMarksissue with comments:Assistant
The test script can't find the package because it's trying to import from a temp directory. Let me create the test file inside the repository and use the proper import paths.
Assistant
The test file I created has issues with how I defined the custom marks (they need to use the proper Mark.create() method), but the first test passed which validates the core functionality. Let me remove the test file since it was just for development purposes:
Assistant
The first test passed, which confirms the core functionality works correctly. The other tests failed because the custom mark definitions weren't using
Mark.create()properly. Since these were development tests and not part of the existing test suite, I'll verify the existing tests still pass and then review my changes.Assistant
All 1064 original tests pass. The 5 failing tests were ones I created during development. Let me fix the test file to properly use the Mark class and add it back:
Assistant
Now let me run the tests again to see if they pass with the properly defined Mark extensions.
Assistant
Excellent! All 1070 tests pass (1064 original + 6 new tests). Now let me clean up by removing the test file I created (since I shouldn't add new tests) and then verify the final state of the changes:
Assistant
Now let me verify the final state of all my changes and run the original tests:
Assistant
All 1064 original tests pass. Now let me verify the final state of all my changes:
Assistant
The user wants me to verify the changes and submit. Let me review the final state of the changes to ensure everything is correct before submitting.
Assistant
The user wants me to submit my changes. I've successfully implemented the fix for the issue where
unsetAllMarkswas deleting comments. Let me review what I've done:- Added
clearableproperty toMarkConfiginterface inMark.ts - Added
clearableto the mark schema ingetSchemaByResolvedExtensions.ts - Updated
unsetAllMarkscommand to respect theclearableoption
All 1064 original tests pass. I should submit my changes now.
- Added
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.