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 start by understanding the issue. The problem is that
unsetAllMarksis deleting comments when it shouldn't. According to the issue description and evaluation contract:- Marks configured with
clearable: falseshould NOT be removed byunsetAllMarks()by default - Comments should have
clearable: falseby default (they're semantic marks, not formatting marks) unsetAllMarks()should only remove clearable marks
Let me explore the repository structure to understand how this works.
- Marks configured with
Assistant
Let me explore the packages directory to find the relevant files mentioned in the interface description.
Assistant
Let me look at the core package which should have the Mark.ts and unsetAllMarks.ts files mentioned in the interface.
Assistant
Let me first look at the Mark.ts file to understand the current implementation of the
clearableconfiguration option.Assistant
I notice that the
Mark.tsfile doesn't currently have aclearableconfiguration option. According to the issue description and evaluation contract, I need to add this option. Let me also look at the unsetAllMarks command.<tool_call> <function=bash_terminal> <parameter=command> cat /tiptap/packages/core/src/commands/unsetAllMarks.ts </tool_call>
Assistant
Let me look at the unsetAllMarks command file.
Assistant
Now let me also check what other commands are like, and see if there's a
canmethod for unsetAllMarks. Let me also check the comments extension to understand how comments are implemented.<tool_call> <function=bash_terminal> <parameter=command> ls -la /tiptap/packages/extension-comments </tool_call>
Assistant
Let me check the extension-comments directory to understand how comments are implemented.
Assistant
The extension-comments directory doesn't exist. Let me search for it.
Assistant
The comment extension is not in the packages directory. Let me check the issue description more carefully. It mentions the extension is part of the issue, but maybe it's in a separate repository. Let me focus on what I need to do:
- Add a
clearableconfiguration option toMarkConfigin Mark.ts - Modify
unsetAllMarkscommand to respect theclearableoption
Let me also check if there's a
can()method for unsetAllMarks. Let me look at how other commands implementcan()methods.- Add a
Assistant
Let me look at other commands to see how
can()methods are implemented.Assistant
Let me look at the unsetMark command to see how it implements
can()method.Assistant
Let me also check the types file to understand how
can()methods work in Tiptap commands.Assistant
Let me try another search to understand how
can()methods work in Tiptap.Assistant
Let me look at the structure of
can()methods in the commands to understand how to implement them.Assistant
Let me look at the RawCommands type to understand how commands work with
can()methods.Assistant
Let me look for
can()method implementations in the commands folder.Assistant
Let me check how
can()method works by looking at the types file more carefully. Thecan()method might return{ unsetAllMarks: () => boolean }.<tool_call> <function=bash_terminal> <parameter=command> grep -n "unsetMark|unsetAllMarks" /tiptap/packages/core/src/types.ts | head -20 </tool_call>
Assistant
Let me search for how unsetMark and unsetAllMarks are used in the types file.
Assistant
The output was empty, but the command completed successfully. Let me check if these commands exist at all in the types file.
<tool_call> <function=bash_terminal> <parameter=command> cat /tiptap/packages/core/src/types.ts | grep -i "unset" </tool_call>
Assistant
Let me try again with the correct command format.
Assistant
This means
unsetMarkandunsetAllMarksare not explicitly defined in types.ts - they're probably added via module augmentation in the command files themselves. Let me look at the tests directory to understand better how these commands work.Assistant
The test file count is low. Let me look at the tests in the core package at a different location or check the entire packages structure for tests.
Assistant
Now let me look at the tests for unsetMark to understand how it's being tested.
Assistant
Let me try a more comprehensive search.
Assistant
Now I have a better understanding of the issue. Let me look at how ProseMirror's
removeMarkworks and understand how to check if a mark is clearable.Assistant
Let me look at what the ProseMirror state provides for checking marks:
Assistant
Let me understand how marks are accessed in the state. I need to find a way to check if a mark is clearable.
Assistant
The
clearableoption doesn't exist yet, so I need to add it. Let me now understand the full picture:- First, I need to add
clearableoption to theMarkConfiginterface in Mark.ts - Then, I need to modify the
unsetAllMarkscommand to:- Check if each mark in the selection is clearable
- Only remove clearable marks
- Support the
ignoreClearableoption to remove all marks including non-clearable ones
- Also need to implement the
can()method to check ifunsetAllMarkswould do anything
Let me first check how the schema marks are accessed and see if there's a way to get mark configuration.
<tool_call> <function=bash_terminal> <parameter=command> grep -r "schema.mark" /tiptap/packages/core/src --include=".ts" | head -10 </tool_call>
- First, I need to add
Assistant
Let me search for how mark types are accessed and how their configuration can be retrieved.
Assistant
Looking at unsetMark.ts, I can see it uses
state.schemato get the mark type. Let me explore how to access mark configurations through the schema. First, let me look at what information is available about marks from ProseMirror.Assistant
Let me look at the MarkType interface from ProseMirror to understand what information is available.
<tool_call> <function=bash_terminal> <parameter=command> grep -r "MarkType" /tiptap/packages/core/src/helpers/getMarkType.ts </tool_call>
Assistant
Let me look at how getMarkType works to understand how to access mark configuration.
Assistant
Good. So I can access the mark type from the schema. Now I need to figure out how to get the configuration (like
clearable) for a mark. Let me check if there's a way to access the extension configuration from the schema.Assistant
Let me check how the schema stores information about marks and if I can access the original configuration. In ProseMirror, mark types usually store their configuration.
<tool_call> <function=bash_terminal> <parameter=command> grep -r ".spec|spec:" /tiptap/packages/core/src/Mark.ts </tool_call>
Assistant
Let me look at how marks work in ProseMirror and Tiptap. In ProseMirror, mark types have a
specproperty that contains the original configuration. Let me check if this is accessible.Assistant
Let me look at how a Mark type's spec is accessed. In ProseMirror, MarkType has a spec property.
Assistant
Let me check what a Mark type has access to by looking at the imports from @tiptap/pm/model.
Assistant
Let me check how to access the
specproperty of a MarkType. In ProseMirror, MarkType has aspecproperty that contains the configuration.Assistant
Now I have a clear understanding. Let me implement the fix:
- Add
clearableoption toMarkConfiginterface in Mark.ts - Update the
Markclass to setspec.clearableby default totrue - Modify
unsetAllMarkscommand to respect theclearableoption and supportignoreClearable - Implement the
can()method forunsetAllMarks
Let me start by modifying the Mark.ts file:
- Add
Assistant
Now let me add the
clearableoption to the Mark.ts file:Assistant
Now let me update the Mark.ts file to add the
clearableoption:Assistant
I need to use the proper edit command format. Let me try again with the correct format.
Assistant
Let me use the correct format for the edit command.
Assistant
It looks like the edit replaced too much of the file. The file is now broken. Let me restore it from git.
<tool_call> <function=bash_terminal> <parameter=command> git checkout /tiptap/packages/core/src/Mark.ts </tool_call>
Assistant
The command failed because I need to use the proper format. Let me try again.
Assistant
The file has been restored. Now let me try the edit command again with proper formatting.
<tool_call> <function=bash_terminal> <parameter=command> edit --file /tiptap/packages/core/src/Mark.ts 143:143 << 'EOF' /**
- 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) } EOF
Assistant
The command didn't work. Let me use the bash_terminal tool to modify the file directly.
Assistant
The file ends at line 145 with
}. Let me use a different approach - I'll create a script that replaces the file content.Assistant
Let me verify the changes were applied correctly.
Assistant
The tail doesn't show the change I wanted. Let me check the MarkConfig interface area.
Assistant
Let me check lines 140-150 to see the current state of the file.
Assistant
Now let me update the
unsetAllMarkscommand to respect theclearableoption and implement thecan()method.Assistant
Now let me update the
unsetAllMarkscommand to:- Add an
ignoreClearableoption - Check if marks are clearable before removing them
- Implement the
can()method
- Add an
Assistant
Now let me verify the changes:
Assistant
Let me fix the implementation. The current approach for finding marks in a range is too complex. Let me use a simpler approach based on ProseMirror's standard way of handling marks.
Assistant
Let me verify the file was created correctly:
<tool_call> <function=bash_terminal> <parameter=command> cat /tiptap/packages/core/src/commands/unsetAllMarks.ts </tool_call>
Assistant
Let me run the command correctly.
Assistant
Now I need to also update the Mark class to set the default value for
clearable. Let me check if the Mark class has aaddStorageor similar hook to set default values for spec options.Let me look at how the Mark spec is created:
<tool_call> <function=bash_terminal> <parameter=command> grep -n "spec" /tiptap/packages/core/src/Mark.ts </tool_call>
Assistant
The output is empty. Let me search for how mark specs are created.
Assistant
I can see that marks have a
specproperty with various fields. Now I need to check how Tiptap creates mark specs. Let me look for how marks are extended and how default values are set.Let me look at the Extendable class and how it creates specs.
Assistant
I see the Extendable class has an
extendMarkSchemamethod. Let me search for how Mark specs are created.<tool_call> <function=bash_terminal> <parameter=command> grep -r "extendMarkSchema" /tiptap/packages/core/src --include="*.ts" -A 5 </tool_call>
Assistant
Let me search more specifically for how mark specs are built in Tiptap.
Assistant
Let me look at how mark specs are created in the schema helper file.
Assistant
Let me see more of this file to understand how the mark spec is constructed and where I can add the
clearabledefault.Assistant
Let me check how the Mark spec is fully created to add a default for
clearable.<tool_call> <function=bash_terminal> <parameter=command> sed -n '220,250p' /tiptap/packages/core/src/helpers/getSchemaByResolvedExtensions.ts </tool_call>
Assistant
Let me get the rest of the schema creation section.
Assistant
Now I understand how the Mark spec is created. I need to add a default value for
clearable. The best place to do this is in thegetSchemaByResolvedExtensions.tsfile when building the mark schema.Let me also check the imports and structure of this file.
Assistant
Now I need to modify the file to add a default value for
clearablein the mark schema. Let me find the exact location where the schema is created and add theclearabledefault.Assistant
Let me modify the file to add a default value for
clearable:Assistant
Now let me add the
clearablefield to the schema. I'll replace line 200 to add the clearable field.Assistant
Let me verify the change was applied correctly:
Assistant
Now I need to add a default value for
clearablewhen it's not set. Looking at the code, I need to ensure it defaults totrue. Let me check how thecallOrReturnworks:Assistant
The
callOrReturnreturns the value directly if it's not a function. The issue is that whenclearableisundefined, it will returnundefinedinstead oftrue. I need to provide a default value. Let me modify the code to provide a default value oftrue.Assistant
Let me verify the change:
Assistant
Now I have added:
- The
clearableoption to theMarkConfiginterface - The default value of
trueforclearablein the mark schema creation - The
unsetAllMarkscommand to respect theclearableoption and supportignoreClearable
Now I need to test that my changes work. Let me check if there are any tests related to
unsetAllMarksthat I should run.- The
Assistant
Let me check if there are specific tests for unsetMark and unsetAllMarks:
<tool_call> <function=bash_terminal> <parameter=command> grep -r "unsetAllMarks" /tiptap/packages --include=".test.ts" --include=".spec.ts" 2>/dev/null | head -10 </tool_call>
Assistant
Let me try to build the project to check for any syntax errors:
Assistant
The build seems to be running. Let me wait for it to complete or check for any errors:
<tool_call> <function=bash_terminal> <parameter=command> cd /tiptap && npm run build 2>&1 | tail -50 </tool_call>
Assistant
The command was not executed as a proper function call. Let me try again with the bash_terminal tool.
Assistant
The build failed with a TypeScript error. The issue is with the
can()method definition. Let me look at howcan()methods are defined in other commands.The error is:
codeType '{ unsetAllMarks: (options?: { ignoreClearable?: boolean | undefined; } | undefined) => boolean; }' is not assignable to type '(...args: any[]) => Command'.I need to understand how
can()methods work in Tiptap. Let me check another command that has acan()method.Let me look at how
can()methods work in other commands:<tool_call> <function=bash_terminal> <parameter=command> grep -rn "can:" /tiptap/packages/core/src/commands/*.ts | head -20 </tool_call>
Assistant
Let me try again with the correct bash_terminal syntax.
Assistant
That's my new code. Let me search for how other commands define
can()methods.<tool_call> <function=bash_terminal> <parameter=command> grep -rn "can." /tiptap/packages/core/src/commands/*.ts | head -20 </tool_call>
Assistant
The bash_terminal command is not being invoked properly. Let me try a different approach to search for can() methods.
Assistant
Let me try to understand how
can()methods work in Tiptap by looking at the types file.<tool_call> <function=bash_terminal> <parameter=command> grep -n "can" /tiptap/packages/core/src/types.ts | head -30 </tool_call>
Assistant
I see the pattern now - the shell prompts are working but my grep output is being captured. Let me try a different approach to understand the
can()method structure.Looking at the error message, the issue is that the
canproperty in the command interface needs to have a specific structure. The error says:codeType '{ unsetAllMarks: (options?: { ignoreClearable?: boolean | undefined; } | undefined) => boolean; }' is not assignable to type '(...args: any[]) => Command'.This suggests that
canexpects a function, not an object. Let me look at how other commands define theircan()method structure.Assistant
Let me look at the
CanCommandstype definition to understand the expected structure:Assistant
Let me look at the
SingleCommandstype to understand howcan()methods work:Assistant
Let me search for how
can()is used in command definitions:Assistant
Let me look at how other commands define their
canmethods. The issue is that mycandefinition in the module augmentation is incorrect. Let me check the types file more carefully.Assistant
Now I understand the structure. Looking at the error, the issue is that I defined
can: { unsetAllMarks: ... }but thecanmethod expects a different structure. Let me look at how other commands define thecan()method in the module augmentation.Let me look at a command that has a
can()method defined in its augmentation:Assistant
Let me look at the types for how commands with
canare defined:Assistant
Let me try a different approach. Looking at the error message, the issue is that I'm defining
can: { unsetAllMarks: ... }but thecanproperty in the command interface expects a different type. Let me look at how commands withcanare defined in the types file.I'll look at the type definition for
Commandsinterface in the module augmentation pattern.Assistant
Let me look at how the commands interface is defined in types.ts to understand the correct structure for the
canproperty:<tool_call> <function=bash_terminal> <parameter=command> sed -n '630,660p' /tiptap/packages/core/src/types.ts </tool_call>
Assistant
Let me try to look at the type definitions more carefully. The error suggests that
canis expected to be a function, not an object withunsetAllMarksproperty.Looking at the type
CanCommands = SingleCommands & { chain: () => ChainedCommands }, andSingleCommands = { [Item in keyof UnionCommands]: UnionCommands<boolean>[Item] }, it seems likecanshould be a callable object, not an object containingunsetAllMarks.Let me look at how other commands define their
canmethods. I'll search for howcanis used in the command interface.Assistant
Let me see how the
canmethod is expected to work based on theCommandPropstype. Thecanis defined as() => CanCommands. This meanscanis a function that returnsCanCommands, andCanCommandsisSingleCommands & { chain: () => ChainedCommands }.So
canshould be a function that returns an object with all command methods that return booleans. Let me update my implementation to match this pattern.The issue is that I'm defining
can: { unsetAllMarks: ... }inside theCommandsinterface, but that's not how it works. Thecanproperty inCommandsinterface is automatically generated from the commands.Let me look at how commands with
canmethods are defined. I'll check how thecanproperty works in the module augmentation pattern.Assistant
Let me look at the setMark command to see if it has a
canmethod:Assistant
I see that
setMarkdoesn't explicitly define acanmethod in its interface. This means thecanmethods are generated automatically by thecan()helper function in Tiptap.Looking at the CommandManager code, the
canproperty is a function that returnsCanCommands. Thecanmethod for each command is automatically generated by checking if the command would succeed.Let me look at how
can()methods work in Tiptap. I'll check the helpers for howcanis generated.<tool_call> <function=bash_terminal> <parameter=command> grep -rn "can" /tiptap/packages/core/src/helpers/*.ts | grep -i "unset" | head -10 </tool_call>
Assistant
Let me look at how Tiptap generates
can()methods. Let me check if there's a helper function for this:Assistant
Let me try a different approach. I'll check if the
canmethod is automatically generated by looking at how it's implemented in the CommandManager or the extensions.Looking back at the error message:
codeType '{ unsetAllMarks: (options?: { ignoreClearable?: boolean | undefined; } | undefined) => boolean; }' is not assignable to type '(...args: any[]) => Command'.This suggests that my module augmentation for
canis incorrectly structured. Thecanproperty in theCommandsinterface should not be nested inside the command definition. Instead,canis a separate property of the commands object.Let me look at how the
canproperty works in the type definitions. Based on theCommandPropstype,canis() => CanCommands, andCanCommandsextendsSingleCommands.The issue is that I'm trying to define
caninside the command interface, but that's not how it works. Thecan()method is generated automatically by the framework.Let me check how
can()methods are generated. I'll look for the implementation:Assistant
Let me look at how the commands are used in the Editor or other files to understand how
can()methods work:Assistant
Let me check if there's an extension that adds
cansupport to commands:Assistant
Let me look at the commands extension to see how
can()methods are added:<tool_call> <function=bash_terminal> <parameter=command> cat /tiptap/packages/core/src/extensions/commands.ts </tool_call>
Assistant
The command was not invoked properly. Let me try a different approach - I'll use bash with a different method to get the file content.
Assistant
I see that
canmethods are not added through the commands extension. They must be generated automatically. Let me check the Editor.ts or CommandManager.ts to see howcanis handled:Assistant
Let me see the full
canimplementation in CommandManager.ts:Assistant
Assistant
I need to use a different approach. Let me use bash commands with proper quoting to write the file.
Assistant
Now let me verify the file was written correctly and try building again:
Assistant
The file looks correct now. Let me try building again:
Assistant
The build succeeded! Now let me run the existing tests to make sure my changes don't break anything:
<tool_call> <function=bash_terminal> <parameter=command> cd /tiptap && npm test 2>&1 | tail -100 </tool_call>
Assistant
The command was not executed. Let me try again with the proper bash_terminal syntax.
Assistant
Assistant
The command was not executed. Let me try again with the proper bash_terminal syntax.
Assistant
Assistant
The command is still not being executed. Let me try a different approach - I'll check if the file was created:
<tool_call> <function=bash_terminal> <parameter=command> ls -la /tiptap/test_unsetAllMarks.js </tool_call>
Assistant
Let me check if the test file exists and if not, try a different approach to test the functionality:
Assistant
The test file wasn't created. It seems the heredoc approach didn't work as expected. Let me try creating the test file differently. Let me just summarize what I've done and verify the changes are correct by examining the modified files.
Let me check the current state of all my changes:
<tool_call> <function=bash_terminal> <parameter=command> git diff --stat </tool_call>
Assistant
The git diff command is being run but the output is not being displayed properly. Let me try to check the git status and diff in a different way.
Assistant
Good, the changes are tracked. Let me look at the changes in each file:
Assistant
Let me check the other files:
<tool_call> <function=bash_terminal> <parameter=command> git diff packages/core/src/commands/unsetAllMarks.ts </tool_call>
Assistant
The bash command isn't working properly. Let me try a different approach - using the open command to view the file or using sed to view specific lines.
Assistant
Let me check the third file:
<tool_call> <function=bash_terminal> <parameter=command> git diff packages/core/src/helpers/getSchemaByResolvedExtensions.ts </tool_call>
Assistant
The git diff command is not working properly in this environment. Let me try viewing the specific section of the file that I modified.
Assistant
The changes look correct. Let me now summarize the changes I made:
-
Mark.ts - Added the
clearableoption to theMarkConfiginterface:clearable?: boolean | (() => boolean)with a default value oftrue- This allows marks to be configured as non-clearable (e.g., for comments)
-
getSchemaByResolvedExtensions.ts - Added default value handling for
clearable:clearable: callOrReturn(getExtensionField<MarkConfig['clearable']>(extension, 'clearable', context)) ?? true- This ensures that marks without an explicit
clearablesetting default totrue
-
unsetAllMarks.ts - Updated the command to respect the
clearableoption:- Added
ignoreClearableoption to the command parameters - Modified the logic to only remove marks where
clearableistrue(orignoreClearableis )
- Added
-
Assistant
Let me verify the build output exists by running a different command.
Assistant
The build output exists, which means the build succeeded. Let me summarize what I've done and ensure everything is correct before submitting.
Summary of changes:
-
Mark.ts - Added the
clearableconfiguration option to theMarkConfiginterface:typescriptclearable?: boolean | (() => boolean)This allows mark extensions to specify whether they should be removed by
unsetAllMarks(). -
getSchemaByResolvedExtensions.ts - Added the
clearablefield to the mark schema with a default value oftrue:typescriptclearable: callOrReturn(getExtensionField<MarkConfig['clearable']>(extension, 'clearable', context)) ?? true, -
unsetAllMarks.ts - Modified the command to respect the
clearableoption:- Added an optional parameter
-
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.