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
I'll start by exploring the repository structure to understand the codebase and locate relevant files. Let's first get a high-level view.
- Assistant
Let me explore the repository structure more systematically.
- Assistant
Let me look at the packages directory to find the core package and extension-comments.
- Assistant
Let me check all packages to see if there's a comments extension.
- Assistant
I don't see a
extension-commentspackage in the list. The issue mentions "extension-comments" as the affected package. Let me check if there's a comments-related extension somewhere else. Let me search for "comment" in the codebase. - Assistant
Let me look at the core package structure and find the relevant files mentioned in the interface section.
- Assistant
Let me examine the current implementation of both files.
- Assistant
Now let me look at the
unsetAllMarkscommand: - Assistant
Let me look at the existing commands directory and the Extendable class to understand the patterns:
- Assistant
Let me look at the
toggleMark.tsandunsetMark.tsto see how they handle marks: - Assistant
Now let me check how
tr.removeMarkworks and what other mark-related helpers exist: - Assistant
Let me look at how ProseMirror's removeMark works and the structure of the mark configuration:
- Assistant
Let me check the ProseMirror types:
- Assistant
Let me look at how existing marks are defined, and then understand how the
Extendableclass processes configuration: - Assistant
Let me look at the bold extension to understand how marks work.
- Assistant
Let me look at the extension source code for bold:
- Assistant
The extension file is JSX, let me check the actual source file.
- Assistant
Let me read the bold.tsx file to understand the mark configuration structure.
- Assistant
Now let me check how
removeMarkworks in ProseMirror's Transaction, and also look at existing tests: - Assistant
Let me check if there are any existing tests for
unsetAllMarks: - Assistant
No existing tests for unsetAllMarks. Let me check how
removeMarkis used in ProseMirror's transaction and how the marks are accessed. - Assistant
Let me understand how the mark types and their configurations are accessed:
- Assistant
Let me look at how the
toggleMarkcommand accesses mark types and the schema: - Assistant
Now I understand the issue and the needed changes. Let me look at how the
removeMarkfunction works in ProseMirror and how we can access mark configurations. Let me look at how marks are resolved and whattr.removeMarksignature looks like: - Assistant
Let me check the ProseMirror model for Mark type information:
- Assistant
Let me check the prosemirror-transform types to understand removeMark
- Assistant
Now let me understand how the editor resolves mark types and how we can access the
Markextension configuration from aMarkType: - Assistant
Good,
clearabledoesn't exist yet. Now I need to understand how to access the Mark extension's config from within theunsetAllMarkscommand. Let me look at how the editor accesses extension configurations: - Assistant
Let me look at the command context type and how to access editor from within commands:
- Assistant
Let me check the CommandProps type to see what's available:
- Assistant
Good, so we have
editoravailable in the command context. Now let me look at how the editor stores its extensions and how we can access a mark's config by its MarkType. - Assistant
Let me understand how the
schemais structured and how to get mark types from within a command: - Assistant
Let me look at how extensions are stored and accessed from the Editor:
- Assistant
Let me understand how extensions are accessed from the editor and how their configuration is stored:
- Assistant
Now I need to understand how to access a mark's configuration from within the command. Let me see how
keepOnSplit(another MarkConfig property) is accessed: - Assistant
Let me look at how
getExtensionFieldis used to accesskeepOnSplit: - Assistant
Now I understand how
getExtensionFieldworks. Let me now understand the approach for accessing mark configurations from within commands. Let me look at howeditoris used to get extension config: - Assistant
Now let me look at how the extension's config is accessed from within commands. I need to understand how
getExtensionFieldworks with mark extensions: - Assistant
Now I have a clear understanding of the codebase. Let me plan my implementation:
- Add
clearableoption toMarkConfiginterface inMark.ts - Modify
unsetAllMarkscommand to acceptoptions?: { ignoreClearable?: boolean } - Implement the logic to filter marks based on clearability
Let me start by adding the
clearableproperty to the MarkConfig interface. First, let me look at the exact structure of MarkConfig to find the right place to add it: - Add
- Assistant
Let me see the rest of the file
- Assistant
Now let me understand the full picture. I need to check how we can determine the
clearablevalue for each mark type within theunsetAllMarkscommand. Let me look at how extensions are accessed by name/type: - Assistant
Let me look at how the
callOrReturnutility is used and also check the command index: - Assistant
Now I have a good understanding of the codebase. Let me implement the solution:
- Add
clearableoption toMarkConfiginMark.ts - Modify
unsetAllMarkscommand to acceptoptions?: { ignoreClearable?: boolean }and filter marks based on their clearable status
Let me start with the Mark.ts file:
- Add
- Assistant
I see there's a duplicate "Marks this Mark as exitable" comment. Let me fix that:
- Assistant
Good. Now I need to modify the
unsetAllMarkscommand. Let me first understand how to check theclearableconfiguration for each mark type. I need to access the TiptapMarkextension config from the ProseMirrorMarkType. Let me look at how the editor accesses extension config: - Assistant
Let me look at how mark extensions are filtered and accessed in the codebase:
- Assistant
Now I have a clear picture. Let me implement the
unsetAllMarkscommand with theclearablelogic. I need to:- Access the editor's extension manager to check mark configurations
- Only remove marks that are clearable (unless
ignoreClearableis true)
Let me now update the
unsetAllMarks.tsfile: - Assistant
Now let me implement the updated
unsetAllMarks.ts. I need to:- Import necessary helpers
- Update the TypeScript declaration to include the
ignoreClearableoption - Implement the logic to filter marks based on their
clearableconfiguration
Let me first look at how
getExtensionFieldis used with mark extensions: - Assistant
Now let me check how we can get mark extensions from the editor's extension manager. Let me look at how the
splitExtensionshelper is used: - Assistant
Now I need to understand how to get from a ProseMirror
MarkTypeto the Tiptap Mark extension to check theclearableconfig. Let me look at how the toggleList command accesses extensions: - Assistant
Now I need to understand how to access the editor's extension configuration from within the command. Let me look at how the
toggleListcommand accesses the editor's extensions and the splittableMarks: - Assistant
Now I have all the pieces I need. Let me implement the
unsetAllMarkscommand. I need to:- Accept
options?: { ignoreClearable?: boolean } - Get the editor's mark extensions
- For each mark in the selection, check if it's clearable
- Only remove clearable marks (unless
ignoreClearableis true)
Let me now write the implementation:
- Accept
- Assistant
Now let me check the Editor type to understand how
extensionStorageworks and verify the context shape: - Assistant
Let me look at how the extensionStorage type is defined and also check how other commands access extension storage:
- Assistant
Let me look at how the
getExtensionFieldis used with context. ThekeepOnSplitexample in ExtensionManager provides a context withname,options,storage,editor,type. But actually, for our case, we need to figure out how to get the clearable value from the extension config. Let me look more carefully.Actually, looking at how
getExtensionFieldworks - it accessesextension.config[field]and if it's a function, it binds the context asthis. So for theclearablefield on MarkConfig, we need to look atextension.config.clearable.But wait, the extension's config doesn't store
clearabledirectly as a field becauseMarkConfigproperties are defined on the interface but they are processed through the extension resolution pipeline. Let me check howkeepOnSplitis actually stored in the extension config.Looking at the
getExtensionFieldfunction:- It first checks
extension.config[field] - If undefined and there's a parent, it recurses to parent
- If it's a function, it binds the context as
- It first checks
- Assistant
Now I understand the pattern. Let me check how
getExtensionFieldworks with the context. I see that insetupExtensions, the context is constructed the same way. Let me simplify the approach - I can usegetExtensionFielddirectly with the context object.Let me also check if there's a simpler way - looking at the
keepOnSplitpattern more closely. It usescallOrReturn(getExtensionField(extension, 'keepOnSplit', context)) ?? true. Let me check whatcallOrReturndoes when givenundefined: - Assistant
Now let me look at how
getExtensionFieldworks to understand if it handles function binding via context or if I needcallOrReturn: - Assistant
I see that
getExtensionFieldalready handles function binding via context. So I can usecallOrReturnto actually call the function. Let me now write the proper implementation forunsetAllMarks.ts.Let me first check how we can get mark types from the schema and map them to extensions:
- Assistant
Now let me also look at how storage is accessed for extensions in commands:
- Assistant
Let me look at how other commands access the editor's extension storage.
- Assistant
Now I understand the full picture. Let me write the proper implementation. I need to:
- Import the necessary helpers (
getExtensionField,splitExtensions,callOrReturn,getSchemaTypeByName) - Get mark extensions from
editor.extensionManager.extensions - For each mark extension, check if
clearableisfalseusinggetExtensionField - Only remove clearable marks (unless
ignoreClearableis true)
Let me also check what
getSchemaTypeByNamedoes: - Import the necessary helpers (
- Assistant
Now let me write the final implementation:
- Assistant
Now let me verify the changes I've made. Let me check if there are any existing tests that might be affected:
- Assistant
No existing tests for
unsetAllMarks. Let me now check if the code compiles correctly by looking at the TypeScript configuration and checking for any type errors: - Assistant
Let me find the right tsconfig path
- Assistant
Let me check the root tsconfig.json:
- Assistant
Let me run the TypeScript compiler to check for type errors:
- Assistant
The TypeScript errors are from demos and node_modules, not from our changes. Let me specifically check if there are any type errors in our modified files:
- Assistant
No type errors in our modified files. Now let me run the existing tests to make sure we haven't broken anything:
- Assistant
All 117 test files passed with 1064 tests passing. Now let me verify the implementation is correct by reviewing the files:
- Assistant
Let me also verify the Mark.ts changes:
- Assistant
Now let me verify the changes by creating a test script to simulate the scenario described in the issue:
- Assistant
Let me look at how the existing tests are structured:
- Assistant
Now let me write a proper test to verify the changes work correctly. Let me check how to run tests:
- Assistant
Let me look at how existing tests for commands are structured, like the cut test:
- Assistant
Let me create a temporary test file to verify our changes work:
- Assistant
Now let me run the test to see if it passes:
- Assistant
All 6 tests passed. Now let me also run the existing tests to make sure we haven't broken anything:
- Assistant
All 118 test files passed with 1070 tests. Our changes don't break any existing tests. Now let me clean up the temporary test file I created (since the instructions say not to add new tests to the repository):
- Assistant
Now let me verify the final state of our changes by looking at the diff:
- Assistant
Let me run all tests one more time to confirm everything is still passing:
- Assistant
All 117 test files passed with 1064 tests. Let me also check if there are any other places in the codebase that reference
unsetAllMarksthat might need updating: - Assistant
Good, there are no other places that reference
unsetAllMarksthat need updating. Let me also verify that the existing demos that useunsetAllMarksstill work by checking if they compile correctly: - Assistant
The demos are calling
unsetAllMarks()without arguments, which is fine because our implementation hasoptions = {}as default. So the existing demos will continue to work as before.Let me now do a final review of all the changes I've made. Let me also check if there are any other related tests that might need updating:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.