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.
Type: Command Name: unsetAllMarks Path: packages/core/src/commands/unsetAllMarks.ts Input: options?: { ignoreClearable?: boolean } Output: ReturnType Description: Removes clearable marks from the current selection. Marks configured with clearable: false are preserved unless ignoreClearable is true. can().unsetAllMarks() returns true when the selection contains only non-clearable marks; this case is a successful no-op.
ADDITIONAL ADVICE
Since you are given a git repository, you can use git commands to simplify your work. For example, if you made a mistake and want to revert your changes, you can use
git checkout <file>to restore the file to its original state. You can also reset all changes in the repository usinggit reset --hardcommand. Additionally, you can usegit stashandgit stash popto temporarily save your changes and restore them later. Finally, you can see the changes that you've made (which will be submitted when you callsubmit) usinggit statusorgit diffcommands. However you don't need to usegit addorgit commitbefore submitting your changes. In fact,submitonly submits currently unstaged changes because it usesgit diffto get the changes that need to be submitted.CHECKLIST
Before submitting your solution, please go over the following checklist and make sure you've done everything:
- If an error was reported in the issue description, I have successfully reproduced it.
- If an error was reported in the issue description, I have confirmed that my fix resolves the error.
- I have thought about edge cases and made sure my fix handles them as well.
- I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass. I want you to list every bullet from this checklist and write your reasoning for why you think you did it or didn't need to.
Repository has been uploaded and your shell is currently at the repository root. Time to solve the issue!
(Current directory: /tiptap, current file: none) bash-$
Assistant
Let me understand the issue:
- The user has a Tiptap editor with a "clear formatting" button that calls
unsetAllMarks - When the selection includes content with comments, the comments are also deleted
- The expected behavior is that
unsetAllMarksshould remove formatting marks but NOT comment tags or comments
According to the evaluation contract:
- Marks are clearable by default
- A mark configured with
clearable: falsemust surviveunsetAllMarks() unsetAllMarks({ignoreClearable: true})removes non-clearable marks- Calling
can().unsetAllMarks()on a selection containing only non-clearable marks returnstrue(successful no-op)
The interface defines:
MarkConfig.clearable- a boolean that controls whether unsetAllMarks removes this mark (default: true)unsetAllMarkscommand - removes clearable marks from selection; preserves non-clearable unless ignoreClearable is true
So I need to:
- Find the comments package extension
- Add a
clearable: falseoption to comment marks - Find the
unsetAllMarkscommand and ensure it respects theclearableconfiguration - Ensure
can().unsetAllMarks()works correctly for non-clearable marks
Let me start by exploring the repository structure to understand the codebase.
- The user has a Tiptap editor with a "clear formatting" button that calls
Assistant
Let me explore the packages directory to find the comments extension and the core package with the unsetAllMarks command.
<tool_call> <function=bash_terminal> <parameter=command> ls -la /tiptap/packages </tool_call>
Assistant
Let me explore the packages directory to find the comments extension and the core package.
Assistant
Let me find the comments extension. It might be in a different location. Let me search for it.
<tool_call> <function=bash_terminal> <parameter=command> find /tiptap -type d -name "comment" 2>/dev/null </tool_call>
Assistant
Let me search for comments directory properly.
Assistant
No comments extension in the packages directory. Let me search for comment in the packages directory more specifically.
<tool_call> <function=bash_terminal> <parameter=command> ls -la /tiptap/packages/ | grep -i comment </tool_call>
Assistant
Let me search for comment in the packages directory more specifically.
Assistant
There's no comment extension in packages. The issue description mentions the comments package. Let me search for where comment-related code might be.
<tool_call> <function=bash_terminal> <parameter=command> find /tiptap/packages -type f -name "*.ts" | xargs grep -l "comment" 2>/dev/null | head -20 </tool_call>
Assistant
Let me search for comment-related files in the packages directory.
Assistant
Let me look at the core package and find the unsetAllMarks command and Mark.ts files.
Assistant
Now let me look at the Mark.ts file to understand its structure:
Assistant
Now let me look at the unsetAllMarks command:
<tool_call> <function=bash_terminal> <parameter=command> cat /tiptap/packages/core/src/commands/unsetAllMarks.ts </tool_call>
Assistant
I need to use a proper tool call format. Let me use bash_terminal again with the correct format.
Assistant
Now I see the issue. The
unsetAllMarkscommand usestr.removeMark()which removes all marks from the selection. I need to:- Add a
clearableoption toMarkConfig(defaulting totrue) - Modify
unsetAllMarksto only remove marks that areclearable: true(orignoreClearableoption is set) - Update
can().unsetAllMarks()to returntruewhen there are only non-clearable marks
Let me also look at the
types.tsto see how commands are structured and howcan()works.<tool_call> <function=bash_terminal> <parameter=command> cat /tiptap/packages/core/src/types.ts </tool_call>
- Add a
Assistant
I need to run the cat command properly. Let me try again.
Assistant
Let me see the Commands type definition to understand how commands and their
can()methods work. Let me search for that.<tool_call> <function=bash_terminal> <parameter=command> grep -n "unsetAllMarks|unsetMark" /tiptap/packages/core/src/types.ts | head -40 </tool_call>
Assistant
The grep command didn't output anything, which suggests the commands might not be in types.ts. Let me search for where the commands are defined.
Assistant
Let me look at the commands index to see how commands are registered.
Assistant
Let me look at the unsetMark command to see how it handles clearable.
Assistant
Now let me look at the setMark command to understand the pattern for how commands check capabilities (can()).
<tool_call> <function=bash_terminal> <parameter=command> cat /tiptap/packages/core/src/commands/setMark.ts </tool_call>
Assistant
I need to run the command properly. Let me try again with the bash_terminal function.
Assistant
Now I need to understand how the commands interface is generated and how
can()is used. Let me look for thecan()method or command registration.<tool_call> <function=bash_terminal> <parameter=command> grep -r "can()" /tiptap/packages/core/src/commands/*.ts 2>/dev/null | head -20 </tool_call>
Assistant
The grep command is failing to produce output. Let me try a different approach to understand how commands work.
Assistant
I see. The
canSetMarkfunction is used bysetMarkto check if the mark can be set, and the command returnscanSetMark()as the result. Forcan().unsetAllMarks(), the command would returntrueif the operation is valid.Now let me understand how the Editor class uses commands and how
can()is implemented. Let me look at the Editor.ts file.Assistant
It seems the grep command exited but didn't find any results, which suggests unsetAllMarks isn't directly in Editor.ts. Let me look at how commands are registered.
Let me now examine how the MarkConfig interface is used and where the clearable property needs to be added. Let me look at the Mark.ts file more closely and understand what properties it has.
Actually, I realize I need to approach this systematically:
- Add
clearableoption toMarkConfiginterface - Modify
unsetAllMarkscommand to checkclearableproperty - Update
can().unsetAllMarks()to work correctly
Let me first understand the current implementation better. Let me look at the Mark class to see how options are stored and accessed.
<tool_call> <function=bash_terminal> <parameter=command> grep -n "addOptions|options|storage" /tiptap/packages/core/src/Mark.ts | head -30 </tool_call>
- Add
Assistant
Let me use a different approach to look at the Mark.ts file. I'll use the
opencommand or just continue using bash_terminal.Assistant
Let me continue viewing the Mark.ts file to see the rest of the interface and the class.
Assistant
Now I need to understand the Extendable class to see how options are stored and accessed.
Let me check the Extendable.ts file.
<tool_call> <function=bash_terminal> <parameter=command> head -100 /tiptap/packages/core/src/Extendable.ts </tool_call>
Assistant
The command seems to not be executing properly. Let me try to view the Extendable.ts file differently.
Assistant
Now I understand the structure better. Let me look for how the Mark class stores the name and type information, and how we can check if a mark is clearable in the unsetAllMarks command.
Let me first check if there's any existing test for unsetAllMarks to understand how it works.
<tool_call> <function=bash_terminal> <parameter=command> find /tiptap -type f -name ".spec.ts" -o -name ".test.ts" | xargs grep -l "unsetAllMarks" 2>/dev/null | head -10 </tool_call>
Assistant
Let me try the find command properly.
Assistant
There's no output from the find command, which means either there are no test files with unsetAllMarks, or the find command didn't work as expected. Let me try a different approach to find test files.
Assistant
Let me look at the can.spec.ts file to understand how can() works for commands.
Assistant
Let me now understand how commands are registered and how the
can()method works. The key is to see how the command system handles thecan()check. Let me look at the Editor.ts file for this.Assistant
Let me look at the CommandManager to understand how the
can()method works.Assistant
I see that
can()passesdispatch: undefinedto the commands, which means the commands should return a boolean indicating whether they can be executed.Now I need to understand the plan:
- Add
clearableoption toMarkConfiginterface (defaulttrue) - Modify
unsetAllMarkscommand to only remove clearable marks - Update
unsetAllMarksto returntruewhen only non-clearable marks are present (no-op case)
Let me also check if there's a comments extension that I should update. First, let me search for any existing comment extension or implementation.
<tool_call> <function=bash_terminal> <parameter=command> find /tiptap -type d -name "extension*" | grep -v node_modules | head -20 </tool_call>
- Add
Assistant
The find command doesn't seem to be producing output. Let me try a different approach to search for the comments extension.
Assistant
There's no comments extension in the packages directory. The issue mentions that the bug is in the
extension-commentspackage, but looking at the evaluation contract and the interface description, the fix should be implemented in the core package by:- Adding
clearableoption toMarkConfig - Modifying
unsetAllMarkscommand to respect theclearableoption
The comments extension (if it exists as a mark) should be able to use this
clearable: falseoption. Let me focus on implementing the core changes first.Let me now create a test to understand the current behavior and verify the fix works.
First, let me add the
clearableoption to theMarkConfiginterface.- Adding
Assistant
Let me now implement the fix. First, I'll add the
clearableoption to theMarkConfiginterface inMark.ts.Assistant
Now I'll add the
clearableoption to theMarkConfiginterface. Let me find the exact line where I should insert it.Assistant
I need to add the
clearableoption to theMarkConfiginterface. Based on the issue description, this option should default totrue. I'll add it after thecodeproperty since it seems to be alphabetically ordered and also relates to mark behavior.Let me view the exact lines around line 93 to understand the structure better.
Assistant
Now I'll add the
clearableoption to the interface. I'll insert it after thecodeproperty, before theparseHTMLproperty. The option should have a default value oftrue.<tool_call> <function=bash_terminal> <parameter=command> sed -n '100,105p' /tiptap/packages/core/src/Mark.ts </tool_call>
Assistant
Let me try a different approach to see the lines around where I need to add the clearable option.
Assistant
Now I need to add the
clearableoption after line 101 (after the code property). Let me use theeditcommand to add it.<tool_call> <function=bash_terminal> <parameter=command> cat > /tmp/clearable_option.txt << 'EOF'
/**
- Controls whether unsetAllMarks removes this mark.
- Set to false for semantic marks (e.g., comments) that should survive clear-formatting operations.
- @default true */ clearable?: boolean | (() => boolean)
EOF cat /tmp/clearable_option.txt </tool_call>
Assistant
Let me try a different approach. I'll use sed to insert the clearable option into the Mark.ts file after the code property.
Assistant
Let me verify the change was made correctly.
<tool_call> <function=bash_terminal> <parameter=command> sed -n '95,115p' /tiptap/packages/core/src/Mark.ts </tool_call>
Assistant
Let me use a different approach to view the changes I made to Mark.ts.
Assistant
The
clearableoption has been added to theMarkConfiginterface. Now I need to:- Modify the
unsetAllMarkscommand to respect theclearableoption - Update the command to return
truewhen only non-clearable marks are present (no-op case)
Let me first look at the current
unsetAllMarksimplementation.<tool_call> <function=bash_terminal> <parameter=command> cat /tiptap/packages/core/src/commands/unsetAllMarks.ts </tool_call>
- Modify the
Assistant
The cat command isn't producing output. Let me use a different approach to view the unsetAllMarks file.
Assistant
Now I understand the current implementation. The
unsetAllMarkscommand usestr.removeMark()which removes all marks from the selection. I need to modify it to:- Check if each mark has
clearable: falsebefore removing it - Only remove marks that are clearable (or if
ignoreClearableoption is set) - Return
truewhen there are only non-clearable marks (no-op case)
Let me check how to get the mark type information. I need to understand how to check if a mark is clearable. The mark type should have access to the extension's options.
Let me look at how other commands access the mark configuration.
<tool_call> <function=bash_terminal> <parameter=command> grep -n "mark.type|schema|extension" /tiptap/packages/core/src/commands/setMark.ts | head -20 </tool_call>
- Check if each mark has
Assistant
I need to use a proper bash command. Let me try again.
Assistant
Now I need to understand how to access the mark's extension configuration. Looking at the code, I can see that
MarkTypeis used. Let me search for how extensions are accessed from the editor state.Assistant
Let me look at how the command props provide access to extensions or the editor. The command function receives
editorin the props.Let me look at the CommandProps type to understand what's available.
Assistant
Let me search for CommandProps definition more specifically.
Assistant
The command exited with exit code 1, which means the grep didn't find any matches. Let me try a different approach.
Assistant
The CommandProps includes
editor: Editor, which gives me access to the editor'sextensionManagerandschema. I can use the schema to get the mark type and access its configuration.Let me look at how marks work in ProseMirror and how to access their configuration. First, let me understand how the
MarkTypeinterface works.Actually, I think the key insight is that the
MarkTypein ProseMirror doesn't directly have access to the Tiptap extension configuration. However, I can access the extension from theeditorvia theextensionManager.Let me look at how to get the mark extension from the editor.
<tool_call> <function=bash_terminal> <parameter=command> grep -n "extensions|getExtension" /tiptap/packages/core/src/Editor.ts | head -20 </tool_call>
Assistant
The command failed again. Let me try a different approach to view the Editor.ts file.
Assistant
I see the Editor has an
extensionManagerproperty. Let me look at the ExtensionManager to understand how to get the extension for a given mark type.<tool_call> <function=bash_terminal> <parameter=command> grep -n "extensions|getExtension" /tiptap/packages/core/src/ExtensionManager.ts | head -20 </tool_call>
Assistant
The command exited with exit code 0, but no output was shown. Let me try a different approach to view the ExtensionManager.
Assistant
The
ExtensionManagerhas anextensionsarray that contains all the extensions. I can search through this array to find the extension by name.Now I need to think about the implementation:
- The
unsetAllMarkscommand needs to check each mark in the selection - For each mark, it needs to check if the mark's extension has
clearable: true(or ifignoreClearableis set) - Only clear marks that are allowed to be cleared
Let me think about how to get the mark extension. The mark type has a
.nameproperty that corresponds to the extension name. I can then search througheditor.extensionManager.extensionsto find the matching extension.Let me now write the new
unsetAllMarkscommand implementation.First, let me understand how to get the clearable value. The
clearableoption can be a boolean or a function that returns a boolean. I need to handle both cases.Here's my plan:
- Modify
unsetAllMarksto accept an optionalignoreClearableparameter - For each range in the selection, get the marks
- For each mark, check if it's clearable (or if
ignoreClearableis true) - Only remove clearable marks
- Return
trueif the operation was successful (including when there are only non-clearable marks)
Let me now modify the
unsetAllMarkscommand:<tool_call> <function=bash_terminal> <parameter=command> cat /tiptap/packages/core/src/commands/unsetAllMarks.ts </tool_call>
- The
Assistant
The cat command is failing to produce output consistently. Let me try a different approach using sed to view the file.
Assistant
Now I can see the current implementation. Let me create the updated version that:
- Accepts an optional
ignoreClearableparameter - Only removes clearable marks (based on the
clearableconfig option) - Returns
truewhen there are only non-clearable marks (no-op case)
Let me write the updated implementation:
<tool_call> <function=bash_terminal> <parameter=command> cat > /tmp/unsetAllMarks.ts << 'EOF' import type { MarkType } from '@tiptap/pm/model'
import { getExtensionField } from '../helpers/getExtensionField.js' import type { RawCommands } from '../types.js'
declare module '@tiptap/core' { interface Commands { unsetAllMarks: { /** * Remove all clearable marks in the current selection. * Marks with
clearable: falseare preserved unlessignoreClearable: trueis passed. * @param options.ignoreClearable - Remove all marks including non-clearable ones. Defaults tofalse. * @example editor.commands.unsetAllMarks() * @example editor.commands.unsetAllMarks({ ignoreClearable: true }) / unsetAllMarks: (options?: { /* * Remove all marks including non-clearable ones. Defaults tofalse. */ ignoreClearable?: boolean }) => ReturnType } } }function isMarkClearable(extension: any): boolean { return getExtensionField(extension, 'clearable', { name: extension.name }) ?? true }
export const unsetAllMarks: RawCommands['unsetAllMarks'] = (options = {}) => ({ tr, editor, dispatch }) => { const { ignoreClearable = false } = options const { selection } = tr const { empty, ranges } = selection
if (empty) { return true } // Track if any marks were actually removed let marksRemoved = false if (dispatch) { ranges.forEach(range => { const { $from, $to } = range const marks = $from.marks() // Get unique marks in the range const uniqueMarks = Array.from(new Set(marks)) uniqueMarks.forEach(mark => { // Get the mark extension to check if it's clearable const markExtension = editor.extensionManager.extensions.find( ext => ext.name === mark.type.name, ) // Skip removal if mark is not clearable and ignoreClearable is not set if (markExtension && !ignoreClearable) { const clearable = isMarkClearable(markExtension) if (!clearable) { return // Skip this mark } } tr.removeMark($from.pos, $to.pos, mark.type) marksRemoved = true }) }) } return true} EOF cat /tmp/unsetAllMarks.ts </tool_call>
- Accepts an optional
Assistant
The cat command is working now. Let me write the updated unsetAllMarks.ts file by replacing the current file.
Assistant
The file wasn't created. Let me try a different approach.
<tool_call> <function=bash_terminal> <parameter=command> ls -la /tmp/ </tool_call>
Assistant
Let me try to write the file directly:
Assistant
The echo command seems to have worked. Let me verify the file was written correctly.
<tool_call> <function=bash_terminal> <parameter=command> head -60 /tiptap/packages/core/src/commands/unsetAllMarks.ts </tool_call>
Assistant
The bash command isn't returning output correctly. Let me try a different approach using the bash_terminal tool properly.
Assistant
The file has been updated. Now I need to check if the implementation is correct. Let me also check if there's a need to update the
can()behavior. According to the evaluation contract:Calling
can().unsetAllMarks()on a selection containing only non-clearable marks is a successful no-op and must returntrueThe current implementation returns
truein all cases, which is correct for thecan()case (sincecan()passesdispatch: undefined).However, I should also consider that the
can()method should returnfalseif the command can't be executed (e.g., if the selection is empty). But in our case, the current implementation returnstruewhen the selection is empty, which is correct for a no-op.Wait, I need to also think about the case where there are marks that need to be removed. The
can()should returntrueif at least one mark can be removed. But according to the evaluation contract:Calling
can().unsetAllMarks()on a selection containing only non-clearable marks is a successful no-op and must returntrueThis means
can().unsetAllMarks()should returntrueeven if there are no marks to remove (because it's a no-op).Let me verify the implementation is correct. Actually, looking at the implementation, I think there's an issue. When
can()is called, it passesdispatch: undefined, and the command returnstrue. But in the actual command execution, we need to check if any marks are actually removed.Wait, looking at the evaluation contract again:
can().unsetAllMarks()returns true when the selection contains only non-clearable marks; this case is a successful no-op.This means
can().unsetAllMarks()should returntruewhen:- The selection is empty (no marks to remove)
- The selection contains only non-clearable marks (no-op)
- The selection contains at least one clearable mark (operation will succeed)
So returning
truein all cases is correct.However, I need to double-check if the implementation properly handles the case where there are no marks at all. Let me trace through:
emptyis true → returntrue(correct)emptyis false,dispatchis undefined (can()case) → skip dispatch, returntrue(correct)emptyis false,dispatchis a function → iterate through marks, remove clearable ones, returntrue(correct)
The implementation looks correct. Now let me also check if there are any other issues. Let me look at the
can().unsetAllMarks()behavior more closely.Actually, I realize there might be an issue. The evaluation contract says:
can().unsetAllMarks()returns true when the selection contains only non-clearable marksBut in the current implementation,
can()will returntrueeven when there are marks to remove. This might not be the intended behavior.Let me think about this more carefully. The
can()method should returntrueif the operation is valid (i.e., will not fail). In this case:unsetAllMarks()will always succeed (it will either remove some marks or do nothing)- So
can().unsetAllMarks()should always returntrue
This seems correct. The evaluation contract is saying that even when there are only non-clearable marks (which means no marks will be removed), the operation is still considered "successful" and returns
true.Now let me verify the fix works by running the tests. But first, let me check if there are any existing tests for
unsetAllMarks.<tool_call> <function=bash_terminal> <parameter=command> find /tiptap -name ".spec.ts" -o -name ".test.ts" | xargs grep -l "unsetAllMarks" 2>/dev/null </tool_call>
Assistant
Let me try to find test files using a different method:
Assistant
No test files found for
unsetAllMarksin the core package tests. Let me also check if the import statement is correct in the unsetAllMarks.ts file.Actually, I notice I imported
MarkTypebut didn't use it. Let me remove the unused import.<tool_call> <function=bash_terminal> <parameter=command> head -5 /tiptap/packages/core/src/commands/unsetAllMarks.ts </tool_call>
Assistant
The command is running but not showing the output properly. Let me try using sed to view the first few lines of the file.
Assistant
I need to remove the unused
MarkTypeimport. Let me do that with sed.<tool_call> <function=bash_terminal> <parameter=command> sed -i '1d' /tiptap/packages/core/src/commands/unsetAllMarks.ts </tool_call>
Assistant
The sed command to delete line 1 has been executed. Now let me verify the file looks correct.
Assistant
The line wasn't deleted. Let me try a different approach to remove the unused import.
<tool_call> <function=bash_terminal> <parameter=command> grep -n "MarkType" /tiptap/packages/core/src/commands/unsetAllMarks.ts </tool_call>
Assistant
Let me remove the unused import using sed with a different pattern.
Assistant
Let me verify the file looks correct now:
Assistant
The file looks correct now. Now I need to think about whether the implementation handles all the edge cases correctly.
Looking at my implementation, I realize there's a potential issue. When
dispatchis undefined (i.e., when called fromcan()), the function doesn't actually check if there are marks to remove or not. It just returnstrue.According to the evaluation contract, this is the correct behavior:
can().unsetAllMarks()should returntruewhen the selection contains only non-clearable marks (successful no-op)
However, I should also consider what happens when there are no marks at all in the selection. In that case, the command should also return
true(it's a no-op).Actually, looking at the original implementation, it returns
truefor all cases, including when the selection is empty. This is correct because:- When the selection is empty, there are no marks to remove, so it's a no-op (returns
true) - When the selection contains only non-clearable marks, there are no marks to remove, so it's a no-op (returns
true) - When the selection contains at least one clearable mark, the marks will be removed (returns
true)
So the current implementation should be correct.
Now let me also consider the
ignoreClearableoption. WhenignoreClearable: trueis passed, all marks should be removed, regardless of theirclearableconfiguration.My implementation handles this correctly:
if (markExtension && !ignoreClearable) { const clearable = isMarkClearable(markExtension) if (!clearable) { return // Skip this mark } }If
ignoreClearableistrue, the condition!ignoreClearableisfalse, so the inner block is skipped and all marks are removed.Now let me write a test script to verify the fix works correctly.
Assistant
Now let me run the test script to verify the fix works:
<tool_call> <function=bash_terminal> <parameter=command> cd /tiptap && npm run test -- --run test_unsetAllMarks.ts 2>&1 | head -100 </tool_call>
Assistant
The command didn't produce any output. Let me try a different approach to run the test. First, let me check what testing framework is being used.
Assistant
Let me try running the test using vitest directly. But first, let me check if the test file needs to be in a specific location.
<tool_call> <function=bash_terminal> <parameter=command> cd /tiptap && npm run test:unit -- test_unsetAllMarks.ts 2>&1 | head -50 </tool_call>
Assistant
The command isn't producing output. Let me try running the test with vitest directly with a different approach.
Assistant
The test file needs to be in the
packagesdirectory with the correct naming convention. Let me move the test file to the correct location.<tool_call> <function=bash_terminal> <parameter=command> mv /tiptap/test_unsetAllMarks.ts /tiptap/packages/core/tests/unsetAllMarks.test.ts </tool_call>
Assistant
Let me check if the file was moved and try running the test again.
Assistant
The file wasn't moved. Let me try moving it again:
Assistant
Good, the file was moved. Let me check if the file exists now:
Assistant
The file exists. Now let me try running the test again:
Assistant
The test ran, but it's not structured as a proper vitest test. Let me look at the output:
-
"After unsetAllMarks: Normal text with bold and comment" - This shows that the bold mark was NOT removed! This is a bug.
-
"Marks before unsetAllMarks: []" - This shows that when I select the text, the marks are empty. This might be because I'm selecting incorrectly.
-
"After unsetAllMarks({ ignoreClearable: true }) on comment-only: comment" - This shows that
ignoreClearable: truepartially removed the comment, which is incorrect.
There are some issues with my test and possibly with my implementation. Let me fix the test first to understand the issue better.
Looking at the output:
- The
unsetAllMarksis not removing the bold mark, which means there's an issue with my implementation - The
ignoreClearable: trueis not working correctly either
Let me check my implementation. The issue might be in how I'm checking for marks or how I'm removing them.
Actually, looking at the output more carefully:
- "Can unsetAllMarks: true" - This is correct
- "After unsetAllMarks: Normal text with bold and comment" - The bold mark was NOT removed, which is the bug!
The issue might be that I'm checking
clearableon the wrong mark. Let me trace through the logic:- I select the bold text (from 18 to 22)
- I call
unsetAllMarks() - The function should iterate through the marks and remove clearable ones
Wait, I see the issue. When I select the text, the marks should be returned by
$from.marks(). But looking at the output,Marks before unsetAllMarks: []shows empty marks. This might be because I'm selecting the wrong position.Let me fix the test to properly select the bold text:
<tool_call> <function=bash_terminal> <parameter=command> cat > /tiptap/packages/core/tests/unsetAllMarks.test.ts << 'EOF' import { Editor } from '@tiptap/core' import Document from '@tiptap/extension-document' import Paragraph from '@tiptap/extension-paragraph' import Text from '@tiptap/extension-text' import { Mark } from '@tiptap/core'
// Create a custom comment mark with clearable: false const Comment = Mark.create({ name: 'comment', addAttributes() { return { id: { default: null, }, } }, parseHTML() { return [{ tag: 'span[data-type="comment"]' }] }, renderHTML({ HTMLAttributes }) { return ['span', { 'data-type': 'comment', ...HTMLAttributes }, 0] }, clearable: false, })
// Create a regular formatting mark (default clearable: true) import Bold from '@tiptap/extension-bold'
describe('unsetAllMarks', () => { it('removes clearable marks but not non-clearable marks', () => { const editor = new Editor({ extensions: [Document, Paragraph, Text, Bold, Comment], content: 'Normal text with bold and comment', })
// The bold text is at position 18-23 (0-indexed) // Select the bold text editor.commands.setTextSelection({ from: 18, to: 23 }) // Check the marks at the selection const marks = editor.state.selection.$from.marks() console.log('Marks at selection:', marks.map(m => m.type.name)) // unsetAllMarks should remove the bold mark but not the comment mark editor.commands.unsetAllMarks() const html = editor.getHTML() console.log('After unsetAllMarks:', html) // Bold should be removed (no <strong> tag) expect(html).not.toContain('<strong>') // Comment should still be there expect(html).toContain('<span data-type="comment">') editor.destroy()})
it('can().unsetAllMarks() returns true for selection with only non-clearable marks', () => { const editor = new Editor({ extensions: [Document, Paragraph, Text, Comment], content: 'comment', })
// Select the comment text editor.commands.setTextSelection({ from: 4, to: 11 }) // can().unsetAllMarks() should return true (successful no-op) const can = editor.can().unsetAllMarks() console.log('can().unsetAllMarks() for non-clearable only:', can) expect(can).toBe(true) editor.destroy()})
it('unsetAllMarks() with ignoreClearable: true removes all marks', () => { const editor = new Editor({ extensions: [Document, Paragraph, Text, Comment], content: 'comment', })
// Select the comment text editor.commands.setTextSelection({ from: 4, to: 11 }) // unsetAllMarks({ ignoreClearable: true }) should remove the comment mark editor.commands.unsetAllMarks({ ignoreClearable: true }) const html = editor.getHTML() console.log('After unsetAllMarks({ ignoreClearable: true }):', html) // Comment should be removed (no <span data-type="comment"> tag) expect(html).not.toContain('<span data-type="comment">') editor.destroy()})
it('unsetAllMarks() is a no-op when selection is empty', () => { const editor = new Editor({ extensions: [Document, Paragraph, Text, Bold], content: 'Normal text', })
// Unset all marks with no selection const result = editor.commands.unsetAllMarks() expect(result).toBe(true) editor.destroy()}) }) EOF cat /tiptap/packages/core/tests/unsetAllMarks.test.ts </tool_call>
-
Assistant
The command ran successfully. Let me now run the test again to see if it properly identifies the issue.
Assistant
I see the same old output still being shown, which suggests the test file wasn't updated properly. The error "No test suite found" means the vitest framework isn't recognizing the test structure.
Let me check the test file content to make sure it was written correctly:
<tool_call> <function=bash_terminal> <parameter=command> head -20 /tiptap/packages/core/tests/unsetAllMarks.test.ts </tool_call>
Assistant
Let me use grep to check the test file:
Assistant
The test file still contains the old content. Let me overwrite it properly:
Assistant
Let me verify the file was written correctly and then run the test again:
Assistant
Now the test file has 5 describe/it blocks. Let me run the test again:
Assistant
The test file is missing the vitest imports. Let me add them:
Assistant
Let me run the test again:
Assistant
The tests reveal two issues with my implementation:
-
"Marks at selection: []" - When I select the bold text, no marks are detected. This suggests that the selection range is not correct, or that the
marks()function returns empty for some reason. -
"After unsetAllMarks({ ignoreClearable: true }): comment" - The
ignoreClearable: trueoption is not removing the mark properly.
Let me analyze the issues:
-
The first issue might be that I'm selecting the wrong range. Let me look at the HTML more carefully:
<p>Normal text with <strong>bold</strong> and <span data-type="comment">comment</span></p>- Position 0:
< - Position 1:
p - Position 2:
> - ...
Actually, let me count the positions:
<p>= 3 chars (0-2)Normal text with= 17 chars (3-19)<strong>= 8 chars (20-27)bold= 4 chars (28-31)</strong>= 9 chars (32-40)
So "bold" is at positions 28-31, not 18-23.
-
The second issue might be that I'm only checking marks at
$from, but the mark might extend beyond that. Let me look at how marks work in ProseMirror.
Actually, looking at the test output more carefully, I see that
marks()returns an empty array when I select the bold text. This is strange. Let me investigate further.Wait, I think I understand the issue now. The
$from.marks()returns the marks that start at$from. But when I select a range, the marks might not start at$from- they might start before$from.Let me look at how to properly get all marks in a range. In ProseMirror, we need to check marks that cover the selection range, not just marks that start at
$from.Let me update my implementation to properly handle this case. I'll need to iterate through the nodes in the selection range and check all marks that overlap with the range.
Let me also check the
ignoreClearableissue. Looking at the output, the comment span is partially removed, which suggests thattr.removeMark()is being called but not removing the entire mark. This might be because I'm removing marks from$fromto$to, but the mark might extend beyond$to.Let me fix the implementation:
<tool_call> <function=bash_terminal> <parameter=command> cat > /tiptap/packages/core/src/commands/unsetAllMarks.ts << 'EOF' import { getExtensionField } from '../helpers/getExtensionField.js' import type { RawCommands } from '../types.js'
declare module '@tiptap/core' { interface Commands { unsetAllMarks: { /** * Remove all clearable marks in the current selection. * Marks with
clearable: falseare preserved unlessignoreClearable: trueis passed. * @param options.ignoreClearable - Remove all marks including non-clearable ones. Defaults tofalse. * @example editor.commands.unsetAllMarks() * @example editor.commands.unsetAllMarks({ ignoreClearable: true }) / unsetAllMarks: (options?: { /* * Remove all marks including non-clearable ones. Defaults tofalse. */ ignoreClearable?: boolean }) => ReturnType } } }function isMarkClearable(extension: any): boolean { return getExtensionField(extension, 'clearable', { name: extension.name }) ?? true }
export const unsetAllMarks: RawCommands['unsetAllMarks'] = (options = {}) => ({ tr, editor, dispatch }) => { const { ignoreClearable = false } = options const { selection } = tr const { empty, ranges } = selection
if (empty) { return true } if (dispatch) { ranges.forEach(range => { const { $from, $to } = range // Get all marks that overlap with this range // We need to check marks on all nodes in the range editor.state.doc.nodesBetween($from.pos, $to.pos, node => { // Get marks on this node node.marks.forEach(mark => { // Check if mark is clearable const markExtension = editor.extensionManager.extensions.find( ext => ext.name === mark.type.name, ) // Skip removal if mark is not clearable and ignoreClearable is not set if (markExtension && !ignoreClearable) { const clearable = isMarkClearable(markExtension) if (!clearable) { return // Skip this mark } } // Remove the mark from its current range tr.removeMark(mark.from, mark.to, mark.type) }) }) }) } return true} EOF
-
Assistant
The command was written successfully. Let me run the tests again to see if the fix works.
Assistant
The tests are still failing. The issue is that:
- The marks are not being detected properly because I'm iterating over nodes, but marks are attached to text nodes, not the parent nodes I'm iterating over.
- The
ignoreClearable: trueis still not working correctly.
Let me think about this more carefully. The issue is that
nodesBetweeniterates over all nodes in the range, but it returns the nodes themselves, not the text content with marks. I need to check the marks on each text node.Actually, looking at the ProseMirror API, I should use
doc.nodesBetweenbut iterate only over leaf nodes (text nodes). Let me update the implementation.Also, the issue with
ignoreClearablemight be that I'm removing marks that extend beyond the selection range. When I calltr.removeMark(mark.from, mark.to, mark.type), I'm removing the entire mark. But if the selection only covers part of the mark, the mark should still exist outside the selection.Wait, looking at the output
<p><span data-type="comment">com</span>ment</p>, it seems like the mark was partially removed, which is incorrect. This might be because ProseMirror is interpreting the range incorrectly.Let me think about this differently. The issue might be that:
- I'm not iterating over the correct nodes (I need to iterate over text nodes specifically)
- The mark removal is not working as expected
Let me look at how
tr.removeMarkworks. According to ProseMirror docs,removeMark(from, to, type)removes the mark of the given type from the range [from, to).Actually, I think I understand the issue now. When I use
nodesBetween, I'm getting the node objects, but I need to check if the node is a text node to get its marks.Let me fix the implementation:
<tool_call> <function=bash_terminal> <parameter=command> cat > /tiptap/packages/core/src/commands/unsetAllMarks.ts << 'EOF' import { getExtensionField } from '../helpers/getExtensionField.js' import type { RawCommands } from '../types.js'
declare module '@tiptap/core' { interface Commands { unsetAllMarks: { /** * Remove all clearable marks in the current selection. * Marks with
clearable: falseare preserved unlessignoreClearable: trueis passed. * @param options.ignoreClearable - Remove all marks including non-clearable ones. Defaults tofalse. * @example editor.commands.unsetAllMarks() * @example editor.commands.unsetAllMarks({ ignoreClearable: true }) / unsetAllMarks: (options?: { /* * Remove all marks including non-clearable ones. Defaults tofalse. */ ignoreClearable?: boolean }) => ReturnType } } }function isMarkClearable(extension: any): boolean { return getExtensionField(extension, 'clearable', { name: extension.name }) ?? true }
export const unsetAllMarks: RawCommands['unsetAllMarks'] = (options = {}) => ({ tr, editor, dispatch }) => { const { ignoreClearable = false } = options const { selection } = tr const { empty, ranges } = selection
if (empty) { return true } if (dispatch) { ranges.forEach(range => { const { $from, $to } = range // Track marks that we've already removed to avoid duplicate removals const marksToRemove = new Set<string>() // Iterate over all text nodes in the selection range editor.state.doc.nodesBetween($from.pos, $to.pos, node => { // Only process text nodes if (!node.isText) return // Check if the text node has any marks if (node.marks.length === 0) return node.marks.forEach(mark => { // Get the mark extension to check if it's clearable const markExtension = editor.extensionManager.extensions.find( ext => ext.name === mark.type.name, ) // Skip removal if mark is not clearable and ignoreClearable is not set if (markExtension && !ignoreClearable) { const clearable = isMarkClearable(markExtension) if (!clearable) { return // Skip this mark } } // Create a unique key for this mark (type name + from + to) const markKey = `${mark.type.name}-${mark.from}-${mark.to}` // Only remove if we haven't already scheduled this mark for removal if (!marksToRemove.has(markKey)) { marksToRemove.add(markKey) tr.removeMark(mark.from, mark.to, mark.type) } }) }) }) } return true} EOF
Assistant
The command was written. Let me run the tests again to see if the fix works.
Assistant
The tests are still failing. Let me think about this more carefully.
Looking at the test output:
-
"Marks at selection: []" - This suggests that when I select the bold text,
$from.marks()returns an empty array. This is because the marks are on the text node, but I'm selecting a range that includes the<strong>tags, not just the text. -
The
ignoreClearable: trueissue is still not working.
Let me reconsider the approach. The issue is that:
- When I set a text selection from 18 to 23, I'm selecting the range that includes the HTML tags
<strong>and</strong>, not just the "bold" text. - The ProseMirror transaction's
$fromand$toare resolved positions, not raw indices.
Let me fix the test to select the correct range, and also debug why the implementation isn't working.
Actually, I think the issue is that when I use
setTextSelectionwith raw indices, the positions might be different from what I expect. Let me update the test to use a more reliable method of selecting the bold text.Let me first understand how the content is parsed. When I set content
<p>Normal text with <strong>bold</strong> and <span data-type="comment">comment</span></p>, ProseMirror will parse this and create:- A paragraph node
- Text nodes with marks
The positions in ProseMirror are 0-indexed and refer to the document structure. Let me use a different approach to select the bold text - by toggling the bold mark.
Let me also add some debug logging to see what's happening in the implementation.
Actually, I realize the issue might be simpler. Let me check if the
tr.removeMarkis actually being called. The issue might be that the marks are not being detected in the first place.Let me add some debug logging to the implementation:
<tool_call> <function=bash_terminal> <parameter=command> cat > /tiptap/packages/core/src/commands/unsetAllMarks.ts << 'EOF' import { getExtensionField } from '../helpers/getExtensionField.js' import type { RawCommands } from '../types.js'
declare module '@tiptap/core' { interface Commands { unsetAllMarks: { /** * Remove all clearable marks in the current selection. * Marks with
clearable: falseare preserved unlessignoreClearable: trueis passed. * @param options.ignoreClearable - Remove all marks including non-clearable ones. Defaults tofalse. * @example editor.commands.unsetAllMarks() * @example editor.commands.unsetAllMarks({ ignoreClearable: true }) / unsetAllMarks: (options?: { /* * Remove all marks including non-clearable ones. Defaults tofalse. */ ignoreClearable?: boolean }) => ReturnType } } }function isMarkClearable(extension: any): boolean { return getExtensionField(extension, 'clearable', { name: extension.name }) ?? true }
export const unsetAllMarks: RawCommands['unsetAllMarks'] = (options = {}) => ({ tr, editor, dispatch }) => { const { ignoreClearable = false } = options const { selection } = tr const { empty, ranges } = selection
if (empty) { return true } if (dispatch) { ranges.forEach(range => { const { $from, $to } = range console.log(`[unsetAllMarks] Processing range: $from=${$from.pos}, $to=${$to.pos}`) // Track marks that we've already removed to avoid duplicate removals const marksToRemove = new Set<string>() // Iterate over all text nodes in the selection range editor.state.doc.nodesBetween($from.pos, $to.pos, node => { console.log(`[unsetAllMarks] Processing node: type=${node.type.name}, isText=${node.isText}, marks=${node.marks.length}`) // Only process text nodes if (!node.isText) return // Check if the text node has any marks if (node.marks.length === 0) return node.marks.forEach(mark => { console.log(`[unsetAllMarks] Found mark: type=${mark.type.name}, from=${mark.from}, to=${mark.to}`) // Get the mark extension to check if it's clearable const markExtension = editor.extensionManager.extensions.find( ext => ext.name === mark.type.name, ) // Skip removal if mark is not clearable and ignoreClearable is not set if (markExtension && !ignoreClearable) { const clearable = isMarkClearable(markExtension) console.log(`[unsetAllMarks] Mark ${mark.type.name} is ${clearable ? 'clearable' : 'NOT clearable'}`) if (!clearable) { return // Skip this mark } } // Create a unique key for this mark (type name + from + to) const markKey = `${mark.type.name}-${mark.from}-${mark.to}` // Only remove if we haven't already scheduled this mark for removal if (!marksToRemove.has(markKey)) { marksToRemove.add(markKey) console.log(`[unsetAllMarks] Removing mark ${mark.type.name} from ${mark.from} to ${mark.to}`) tr.removeMark(mark.from, mark.to, mark.type) } }) }) }) } return true} EOF
-
Assistant
Let me run the test again to see the debug output and understand what's happening.
Assistant
The debug output isn't showing up, which suggests the command isn't being executed or the console.log isn't working in the test context. Let me check if the file was updated correctly.
<tool_call> <function=bash_terminal> <parameter=command> head -50 /tiptap/packages/core/src/commands/unsetAllMarks.ts </tool_call>
Assistant
Let me check the file content using a different approach:
Assistant
The file wasn't updated with the debug logging. Let me check what the current content of the file is:
Assistant
I see, the file has the old content. The heredoc command might have failed silently. Let me try a different approach - I'll use a temp file to write the content.
Assistant
The heredoc succeeded. Let me copy the file to the correct location:
Assistant
The file has been updated. Now let me run the test again:
Assistant
The test is still failing. I notice:
-
"After unsetAllMarks({ ignoreClearable: true }): comment" - This is now different from before. The comment is no longer partially removed. This is progress, but the test expects the comment to be removed.
-
The first test is still failing because the bold marks aren't being removed.
The issue is that I'm not finding any marks. Looking at the test output:
- "Marks at selection: []" - The
$from.marks()returns an empty array when I select the bold text.
This suggests that my test selection range (18-23) doesn't actually cover the bold text in the ProseMirror document structure. Let me debug this by understanding how the document is structured.
Actually, I think the problem is with my test. When I set content with HTML like
<p>Normal text with <strong>bold</strong> and <span data-type="comment">comment</span></p>, ProseMirror parses this and creates a document structure. The positions I'm using might not correspond to the text I expect.Let me update the test to use a more reliable method of selecting the bold text - by toggling the bold mark and checking its position.
Actually, let me first understand the document structure by checking what happens when I toggle the bold mark:
<tool_call> <function=bash_terminal> <parameter=command> cat > /tiptap/packages/core/tests/unsetAllMarks.test.ts << 'ENDTEST' import { describe, expect, it } from 'vitest' import { Editor } from '@tiptap/core' import Document from '@tiptap/extension-document' import Paragraph from '@tiptap/extension-paragraph' import Text from '@tiptap/extension-text' import { Mark } from '@tiptap/core'
// Create a custom comment mark with clearable: false const Comment = Mark.create({ name: 'comment', addAttributes() { return { id: { default: null, }, } }, parseHTML() { return [{ tag: 'span[data-type="comment"]' }] }, renderHTML({ HTMLAttributes }) { return ['span', { 'data-type': 'comment', ...HTMLAttributes }, 0] }, clearable: false, })
// Create a regular formatting mark (default clearable: true) import Bold from '@tiptap/extension-bold'
describe('unsetAllMarks', () => { it('removes clearable marks but not non-clearable marks', () => { const editor = new Editor({ extensions: [Document, Paragraph, Text, Bold, Comment], content: 'Normal text with bold and comment', })
// Toggle bold on "Normal text" to create a clear selection with marks editor.commands .setTextSelection(0) .setMark('bold') const htmlBefore = editor.getHTML() console.log('After setting bold:', htmlBefore) // Now select the bold text editor.commands.selectTextblockEnd() // Check the marks at the selection const marks = editor.state.selection.$from.marks() console.log('Marks at end:', marks.map(m => m.type.name)) // unsetAllMarks should remove the bold mark but not the comment mark editor.commands.unsetAllMarks() const html = editor.getHTML() console.log('After unsetAllMarks:', html) // Bold should be removed (no <strong> tag on "Normal text") expect(html).not.toContain('<strong>Normal text') // Comment should still be there expect(html).toContain('<span data-type="comment">') editor.destroy()})
it('can().unsetAllMarks() returns true for selection with only non-clearable marks', () => { const editor = new Editor({ extensions: [Document, Paragraph, Text, Comment], content: 'comment', })
// Select the comment text editor.commands.setTextSelection({ from: 4, to: 11 }) // can().unsetAllMarks() should return true (successful no-op) const can = editor.can().unsetAllMarks() console.log('can().unsetAllMarks() for non-clearable only:', can) expect(can).toBe(true) editor.destroy()})
it('unsetAllMarks() with ignoreClearable: true removes all marks', () => { const editor = new Editor({ extensions: [Document, Paragraph, Text, Comment], content: 'comment', })
// Select the comment text editor.commands.setTextSelection({ from: 4, to: 11 }) // unsetAllMarks({ ignoreClearable: true }) should remove the comment mark editor.commands.unsetAllMarks({ ignoreClearable: true }) const html = editor.getHTML() console.log('After unsetAllMarks({ ignoreClearable: true }):', html) // Comment should be removed (no <span data-type="comment"> tag) expect(html).not.toContain('<span data-type="comment">') editor.destroy()})
it('unsetAllMarks() is a no-op when selection is empty', () => { const editor = new Editor({ extensions: [Document, Paragraph, Text, Bold], content: 'Normal text', })
// Unset all marks with no selection const result = editor.commands.unsetAllMarks() expect(result).toBe(true) editor.destroy()}) }) ENDTEST
-
Assistant
Let me run the test to see the output:
Assistant
The test output is still showing "Marks at selection: []" which means my selection logic is not finding the marks. The issue is that I'm checking
editor.state.selection.$from.marks(), but this only returns marks that START at that position, not marks that cover that position.Let me debug by printing more information about the document structure. Also, I need to understand why
ignoreClearable: trueisn't removing the comment mark.Looking at the test output:
- "Marks at selection: []" - This is printed from the first test, which means my code isn't detecting the marks at all.
Wait, I see the issue. The output says "Marks at selection: []" but my implementation uses
nodesBetweento iterate over nodes. The issue is thatnodesBetweenmight not be finding any text nodes with marks in the range, or my code isn't being executed.Let me add some debug output to see if my code is actually being called. I'll modify the unsetAllMarks.ts file to add logging.
Actually, let me take a different approach. Instead of trying to debug, let me check if the implementation is correct by looking at how
tr.removeMarkworks and what the expected behavior is.Looking at the issue more carefully:
- The test sets content with
<strong>bold</strong>and<span data-type="comment">comment</span> - The test tries to select "Normal text" and toggle bold
- The test expects
unsetAllMarksto remove the bold mark
The problem might be that my
nodesBetweeniteration isn't finding the text nodes correctly, or the mark removal isn't working as expected.Let me check if the issue is with how I'm detecting marks. When I use
nodesBetween($from.pos, $to.pos), I'm iterating over all nodes in the range. But marks are attached to text nodes, so I need to check each text node's marks.Wait, I just realized something. The test output shows "After unsetAllMarks: Normal text with bold and comment" - which is the SAME as the original content! This means my
unsetAllMarksimplementation isn't doing anything.Let me check if the
dispatchfunction is being called correctly. The issue might be that whencan().unsetAllMarks()is called, it passesdispatch: undefined, but when the actual command is called,dispatchshould be a function.Actually, looking at the test more carefully, I see that the first test outputs "Marks at selection: []" - but this is from my test code, not from the unsetAllMarks implementation. The test code checks
editor.state.selection.$from.marks()after setting the selection, and it returns an empty array.This suggests that when I toggle bold on "Normal text", the mark isn't being applied correctly, or the selection is not where I expect it to be.
Let me simplify the test and focus on understanding the document structure:
<tool_call> <function=bash_terminal> <parameter=command> cat > /tiptap/packages/core/tests/unsetAllMarks.test.ts << 'ENDTEST' import { describe, expect, it } from 'vitest' import { Editor } from '@tiptap/core' import Document from '@tiptap/extension-document' import Paragraph from '@tiptap/extension-paragraph' import Text from '@tiptap/extension-text' import { Mark } from '@tiptap/core'
// Create a custom comment mark with clearable: false const Comment = Mark.create({ name: 'comment', addAttributes() { return { id: { default: null, }, } }, parseHTML() { return [{ tag: 'span[data-type="comment"]' }] }, renderHTML({ HTMLAttributes }) { return ['span', { 'data-type': 'comment', ...HTMLAttributes }, 0] }, clearable: false, })
// Create a regular formatting mark (default clearable: true) import Bold from '@tiptap/extension-bold'
describe('unsetAllMarks', () => { it('removes clearable marks but not non-clearable marks', () => { const editor = new Editor({ extensions: [Document, Paragraph, Text, Bold, Comment], })
// Start with empty content editor.commands.setContent('<p>Hello <strong>bold</strong> world</p>') console.log('Content:', editor.getHTML()) // Select the bold word using chain editor.chain().selectTextblockStart().run() const selection = editor.state.selection console.log('Selection from:', selection.from, 'to:', selection.to) // Check marks const marks = editor.state.selection.$from.marks() console.log('Marks at $from:', marks.map(m => m.type.name)) // Toggle bold to apply it editor.chain().toggleBold().run() console.log('After toggleBold:', editor.getHTML()) // Check marks again const marks2 = editor.state.selection.$from.marks() console.log('Marks after toggleBold:', marks2.map(m => m.type.name)) // Now unset all marks editor.commands.unsetAllMarks() console.log('After unsetAllMarks:', editor.getHTML()) // Bold should be removed const html = editor.getHTML() expect(html).not.toContain('<strong>bold</strong>') expect(html).toContain('Hello ') editor.destroy()})
it('can().unsetAllMarks() returns true for selection with only non-clearable marks', () => { const editor = new Editor({ extensions: [Document, Paragraph, Text, Comment], content: 'comment', })
// Select the comment text editor.commands.setTextSelection({ from: 4, to: 11 }) // can().unsetAllMarks() should return true (successful no-op) const can = editor.can().unsetAllMarks() console.log('can().unsetAllMarks() for non-clearable only:', can) expect(can).toBe(true) editor.destroy()})
it('unsetAllMarks() with ignoreClearable: true removes all marks', () => { const editor = new Editor({ extensions: [Document, Paragraph, Text, Comment], content: 'comment', })
// Select the comment text editor.commands.setTextSelection({ from: 4, to: 11 }) // unsetAllMarks({ ignoreClearable: true }) should remove the comment mark editor.commands.unsetAllMarks({ ignoreClearable: true }) const html = editor.getHTML() console.log('After unsetAllMarks({ ignoreClearable: true }):', html) // Comment should be removed (no <span data-type="comment"> tag) expect(html).not.toContain('<span data-type="comment">') editor.destroy()})
it('unsetAllMarks() is a no-op when selection is empty', () => { const editor = new Editor({ extensions: [Document, Paragraph, Text, Bold], content: 'Normal text', })
// Unset all marks with no selection const result = editor.commands.unsetAllMarks() expect(result).toBe(true) editor.destroy()}) }) ENDTEST
Assistant
Let me run the test to see the debug output:
Assistant
The output shows "Marks at selection: []" which is from the old test. The test file might not have been updated. Let me verify the test file content:
<tool_call> <function=bash_terminal> <parameter=command> head -35 /tiptap/packages/core/tests/unsetAllMarks.test.ts </tool_call>
Assistant
Let me verify the test file was updated correctly:
Assistant
The test file doesn't have the new content. Let me update it properly:
<tool_call> <function=bash_terminal> <parameter=command> cat > /tmp/test.ts << 'ENDTEST' import { describe, expect, it } from 'vitest' import { Editor } from '@tiptap/core' import Document from '@tiptap/extension-document' import Paragraph from '@tiptap/extension-paragraph' import Text from '@tiptap/extension-text' import { Mark } from '@tiptap/core'
// Create a custom comment mark with clearable: false const Comment = Mark.create({ name: 'comment', addAttributes() { return { id: { default: null, }, } }, parseHTML() { return [{ tag: 'span[data-type="comment"]' }] }, renderHTML({ HTMLAttributes }) { return ['span', { 'data-type': 'comment', ...HTMLAttributes }, 0] }, clearable: false, })
// Create a regular formatting mark (default clearable: true) import Bold from '@tiptap/extension-bold'
describe('unsetAllMarks', () => { it('removes clearable marks but not non-clearable marks', () => { const editor = new Editor({ extensions: [Document, Paragraph, Text, Bold, Comment], })
// Start with empty content editor.commands.setContent('<p>Hello <strong>bold</strong> world</p>') console.log('Content:', editor.getHTML()) // Select the bold word using chain editor.chain().selectTextblockStart().run() const selection = editor.state.selection console.log('Selection from:', selection.from, 'to:', selection.to) // Check marks const marks = editor.state.selection.$from.marks() console.log('Marks at $from:', marks.map(m => m.type.name)) // Toggle bold to apply it editor.chain().toggleBold().run() console.log('After toggleBold:', editor.getHTML()) // Check marks again const marks2 = editor.state.selection.$from.marks() console.log('Marks after toggleBold:', marks2.map(m => m.type.name)) // Now unset all marks editor.commands.unsetAllMarks() console.log('After unsetAllMarks:', editor.getHTML()) // Bold should be removed const html = editor.getHTML() expect(html).not.toContain('<strong>bold</strong>') expect(html).toContain('Hello ') editor.destroy()})
it('can().unsetAllMarks() returns true for selection with only non-clearable marks', () => { const editor = new Editor({ extensions: [Document, Paragraph, Text, Comment], content: 'comment', })
// Select the comment text editor.commands.setTextSelection({ from: 4, to: 11 }) // can().unsetAllMarks() should return true (successful no-op) const can = editor.can().unsetAllMarks() console.log('can().unsetAllMarks() for non-clearable only:', can) expect(can).toBe(true) editor.destroy()})
it('unsetAllMarks() with ignoreClearable: true removes all marks', () => { const editor = new Editor({ extensions: [Document, Paragraph, Text, Comment], content: 'comment', })
// Select the comment text editor.commands.setTextSelection({ from: 4, to: 11 }) // unsetAllMarks({ ignoreClearable: true }) should remove the comment mark editor.commands.unsetAllMarks({ ignoreClearable: true }) const html = editor.getHTML() console.log('After unsetAllMarks({ ignoreClearable: true }):', html) // Comment should be removed (no <span data-type="comment"> tag) expect(html).not.toContain('<span data-type="comment">') editor.destroy()})
it('unsetAllMarks() is a no-op when selection is empty', () => { const editor = new Editor({ extensions: [Document, Paragraph, Text, Bold], content: 'Normal text', })
// Unset all marks with no selection const result = editor.commands.unsetAllMarks() expect(result).toBe(true) editor.destroy()}) }) ENDTEST cp /tmp/test.ts /tiptap/packages/core/tests/unsetAllMarks.test.ts </tool_call>
Assistant
The command ran but I need to verify the test file was updated. Let me check the content and run the test again.
Assistant
The test file was updated. Now let me run the test to see the debug output:
Assistant
The output shows "Marks at selection: []" which is still from the old test code. The test file content seems to not be reflected. This is strange.
Wait, looking at the test output more carefully:
- "Marks at selection: []" - This is from
console.log('Marks at $from:', marks.map(m => m.type.name))in my test - "After unsetAllMarks: Normal text with bold and comment" - This shows the OLD test content, not the new one
This means the test file wasn't updated correctly or there's some caching issue. Let me check if the test file is really what I think it is:
<tool_call> <function=bash_terminal> <parameter=command> wc -l /tiptap/packages/core/tests/unsetAllMarks.test.ts </tool_call>
- "Marks at selection: []" - This is from
Assistant
The command is running but not showing output. Let me try a different approach to check the test file.
Assistant
The test file doesn't have "selectTextblockStart", which means the new content wasn't written. The cat command might have failed silently. Let me try a different approach to update the test file.
<tool_call> <function=bash_terminal> <parameter=command> rm /tiptap/packages/core/tests/unsetAllMarks.test.ts && cat > /tiptap/packages/core/tests/unsetAllMarks.test.ts << 'EOF' import { describe, expect, it } from 'vitest' import { Editor } from '@tiptap/core' import Document from '@tiptap/extension-document' import Paragraph from '@tiptap/extension-paragraph' import Text from '@tiptap/extension-text' import { Mark } from '@tiptap/core' import Bold from '@tiptap/extension-bold'
// Create a custom comment mark with clearable: false const Comment = Mark.create({ name: 'comment', addAttributes() { return { id: { default: null } } }, parseHTML() { return [{ tag: 'span[data-type="comment"]' }] }, renderHTML({ HTMLAttributes }) { return ['span', { 'data-type': 'comment', ...HTMLAttributes }, 0] }, clearable: false, })
describe('unsetAllMarks', () => { it('removes clearable marks but not non-clearable marks', () => { const editor = new Editor({ extensions: [Document, Paragraph, Text, Bold, Comment], }) editor.commands.setContent('Hello bold world')
// Toggle bold to create a bold mark editor.chain().toggleBold().run() const htmlBefore = editor.getHTML() console.log('Before unsetAllMarks:', htmlBefore) // Unset all marks editor.commands.unsetAllMarks() const html = editor.getHTML() console.log('After unsetAllMarks:', html) expect(html).not.toContain('<strong>') editor.destroy()})
it('can().unsetAllMarks() returns true for selection with only non-clearable marks', () => { const editor = new Editor({ extensions: [Document, Paragraph, Text, Comment], content: 'comment', }) editor.commands.setTextSelection({ from: 4, to: 11 }) const can = editor.can().unsetAllMarks() console.log('can().unsetAllMarks() for non-clearable only:', can) expect(can).toBe(true) editor.destroy() })
it('unsetAllMarks() with ignoreClearable: true removes all marks', () => { const editor = new Editor({ extensions: [Document, Paragraph, Text, Comment], content: 'comment', }) editor.commands.setTextSelection({ from: 4, to: 11 }) editor.commands.unsetAllMarks({ ignoreClearable: true }) const html = editor.getHTML() console.log('After ignoreClearable:', html) expect(html).not.toContain('') editor.destroy() })
it('unsetAllMarks() is a no-op when selection is empty', () => { const editor = new Editor({ extensions: [Document, Paragraph, Text, Bold], content: 'Normal text', }) const result = editor.commands.unsetAllMarks() expect(result).toBe(true) editor.destroy() }) }) EOF
Assistant
Let me verify the test file was created and run the test:
Assistant
Good, the file exists. Let me check its content and run the test:
Assistant
The file size is still 3503 bytes, so the file wasn't updated. Let me try a different approach:
Assistant
Let me run the test now:
Assistant
The echo command messed up the escaping. Let me create the test file using a simpler approach with a file editor:
Assistant
Now let me run the test:
Assistant
The test is now running, and I can see that after
unsetAllMarks, the bold mark is still there:<p>Hello <strong>bold</strong> world</p>. This confirms that my implementation isn't working correctly.The issue is that when I toggle bold at the cursor position, the mark is stored in the
storedMarks, not applied to the text nodes. When I then callunsetAllMarks, my implementation iterates over text nodes in the selection range, but the bold mark isn't on any text node - it's a stored mark.I need to also handle stored marks. Let me update the implementation to also remove stored marks:
<tool_call> <function=bash_terminal> <parameter=command> cat > /tmp/unsetAllMarks.ts << 'EOF' import { getExtensionField } from '../helpers/getExtensionField.js' import type { RawCommands } from '../types.js'
declare module '@tiptap/core' { interface Commands { unsetAllMarks: { /** * Remove all clearable marks in the current selection. * Marks with
clearable: falseare preserved unlessignoreClearable: trueis passed. * @param options.ignoreClearable - Remove all marks including non-clearable ones. Defaults tofalse. * @example editor.commands.unsetAllMarks() * @example editor.commands.unsetAllMarks({ ignoreClearable: true }) / unsetAllMarks: (options?: { /* * Remove all marks including non-clearable ones. Defaults tofalse. */ ignoreClearable?: boolean }) => ReturnType } } }function isMarkClearable(extension: any): boolean { return getExtensionField(extension, 'clearable', { name: extension.name }) ?? true }
export const unsetAllMarks: RawCommands['unsetAllMarks'] = (options = {}) => ({ tr, editor, dispatch }) => { const { ignoreClearable = false } = options const { selection } = tr const { empty, ranges } = selection
if (empty) { return true } if (dispatch) { ranges.forEach(range => { const { $from, $to } = range // Track marks that we've already removed to avoid duplicate removals const marksToRemove = new Set<string>() // Remove stored marks (marks that will be applied to future text) const storedMarks = editor.state.storedMarks?.marks ?? [] storedMarks.forEach(storedMark => { const markExtension = editor.extensionManager.extensions.find( ext => ext.name === storedMark.type.name, ) if (markExtension && !ignoreClearable) { const clearable = isMarkClearable(markExtension) if (!clearable) { return } } tr.removeStoredMark(storedMark.type) }) // Iterate over all text nodes in the selection range editor.state.doc.nodesBetween($from.pos, $to.pos, node => { if (!node.isText) return if (node.marks.length === 0) return node.marks.forEach(mark => { const markExtension = editor.extensionManager.extensions.find( ext => ext.name === mark.type.name, ) if (markExtension && !ignoreClearable) { const clearable = isMarkClearable(markExtension) if (!clearable) { return } } const markKey = `${mark.type.name}-${mark.from}-${mark.to}` if (!marksToRemove.has(markKey)) { marksToRemove.add(markKey) tr.removeMark(mark.from, mark.to, mark.type) } }) }) }) } return true} EOF cp /tmp/unsetAllMarks.ts /tiptap/packages/core/src/commands/unsetAllMarks.ts </tool_call>
Assistant
The file was updated. Let me run the test again to see if the stored marks are now being removed.
Assistant
The test is still failing. The bold mark is still there. Let me think about this more carefully.
When I call
editor.chain().toggleBold().run(), this should apply a bold mark to the selected text. But then when I calleditor.commands.unsetAllMarks(), the bold mark should be removed.Wait, I think the issue is that when I toggle bold with an empty selection (cursor position), the mark is stored but not applied to any text. Then when I call
unsetAllMarks, there's no text selection to remove marks from.Let me update the test to select the text before toggling bold:
<tool_call> <function=bash_terminal> <parameter=command> printf '%s\n' 'import { describe, expect, it } from '"'"'vitest'"'"' import { Editor } from '"'"'@tiptap/core'"'"' import Document from '"'"'@tiptap/extension-document'"'"' import Paragraph from '"'"'@tiptap/extension-paragraph'"'"' import Text from '"'"'@tiptap/extension-text'"'"' import { Mark } from '"'"'@tiptap/core'"'"' import Bold from '"'"'@tiptap/extension-bold'"'"'
const Comment = Mark.create({ name: '"'"'comment'"'"', addAttributes() { return { id: { default: null } } }, parseHTML() { return [{ tag: '"'"'span[data-type="comment"]'"'"' }] }, renderHTML({ HTMLAttributes }) { return ['"'"'span'"'"', { '"'"'data-type'"'"': '"'"'comment'"'"', ...HTMLAttributes }, 0] }, clearable: false, })
describe('"'"'unsetAllMarks'"'"', () => { it('"'"'removes clearable marks but not non-clearable marks'"'"', () => { const editor = new Editor({ extensions: [Document, Paragraph, Text, Bold, Comment], }) editor.commands.setContent('"'"'Hello bold world'"'"')
// Select "bold" text and toggle bold editor.chain().setTextSelection(7).run() editor.chain().extendMarkRange('"'"'bold'"'"').run() editor.chain().toggleBold().run() console.log('"'"'Before unsetAllMarks:'"'"', editor.getHTML()) editor.commands.unsetAllMarks() const html = editor.getHTML() console.log('"'"'After unsetAllMarks:'"'"', html) expect(html).not.toContain('"'"'<strong>'"'"') editor.destroy()}) })' > /tiptap/packages/core/tests/unsetAllMarks.test.ts </tool_call>
Assistant
Let me run the test to see if selecting the text first helps:
Assistant
The test is still failing. Let me think about this more carefully.
The output shows "After unsetAllMarks: Hello bold world", which means the bold mark is still there. But I'm seeing "Before unsetAllMarks" in the console.log statement - but the output shows "After unsetAllMarks:" without the "Before" log first.
Wait, the console.log shows "After unsetAllMarks: Hello bold world" but the test starts with
<p>Hello bold world</p>(without bold). Then I select "bold" text and toggle bold. But the output shows the bold is still there after unsetAllMarks.Let me check if my implementation is actually being called. Maybe the issue is with how I'm iterating over nodes.
Actually, I think I understand the issue now. When I select text and toggle bold, the mark is applied to the selected text nodes. But then when I call
unsetAllMarks, mynodesBetweeniteration might not be finding the text nodes correctly because the selection range might not match the actual text positions.Let me debug by printing out more information about what's happening in my implementation:
<tool_call> <function=bash_terminal> <parameter=command> cat > /tmp/unsetAllMarks.ts << 'EOF' import { getExtensionField } from '../helpers/getExtensionField.js' import type { RawCommands } from '../types.js'
declare module '@tiptap/core' { interface Commands { unsetAllMarks: { /** * Remove all clearable marks in the current selection. * Marks with
clearable: falseare preserved unlessignoreClearable: trueis passed. * @param options.ignoreClearable - Remove all marks including non-clearable ones. Defaults tofalse. * @example editor.commands.unsetAllMarks() * @example editor.commands.unsetAllMarks({ ignoreClearable: true }) / unsetAllMarks: (options?: { /* * Remove all marks including non-clearable ones. Defaults tofalse. */ ignoreClearable?: boolean }) => ReturnType } } }function isMarkClearable(extension: any): boolean { return getExtensionField(extension, 'clearable', { name: extension.name }) ?? true }
export const unsetAllMarks: RawCommands['unsetAllMarks'] = (options = {}) => ({ tr, editor, dispatch }) => { const { ignoreClearable = false } = options const { selection } = tr const { empty, ranges } = selection
console.log(`[unsetAllMarks] empty=${empty}, ranges=${ranges.length}`) if (empty) { return true } if (dispatch) { ranges.forEach((range, rangeIndex) => { const { $from, $to } = range console.log(`[unsetAllMarks] range ${rangeIndex}: $from=${$from.pos}, $to=${$to.pos}`) // Track marks that we've already removed to avoid duplicate removals const marksToRemove = new Set<string>() // Remove stored marks (marks that will be applied to future text) const storedMarks = editor.state.storedMarks?.marks ?? [] console.log(`[unsetAllMarks] storedMarks=${storedMarks.length}`) storedMarks.forEach(storedMark => { console.log(`[unsetAllMarks] storedMark: ${storedMark.type.name}`) const markExtension = editor.extensionManager.extensions.find( ext => ext.name === storedMark.type.name, ) if (markExtension && !ignoreClearable) { const clearable = isMarkClearable(markExtension) console.log(`[unsetAllMarks] storedMark ${storedMark.type.name} is ${clearable ? 'clearable' : 'NOT clearable'}`) if (!clearable) { return } } tr.removeStoredMark(storedMark.type) console.log(`[unsetAllMarks] removed stored mark ${storedMark.type.name}`) }) // Iterate over all text nodes in the selection range console.log(`[unsetAllMarks] iterating nodesBetween from ${$from.pos} to ${$to.pos}`) let textNodeCount = 0 editor.state.doc.nodesBetween($from.pos, $to.pos, node => { textNodeCount++ if (node.isText) { console.log(`[unsetAllMarks] text node: pos=${node.nodeSize}, marks=${node.marks.length}`) if (node.marks.length > 0) { console.log(`[unsetAllMarks] text marks: ${node.marks.map(m => m.type.name).join(', ')}`) } } }) console.log(`[unsetAllMarks] found ${textNodeCount} text nodes`) }) } return true} EOF cp /tmp/unsetAllMarks.ts /tiptap/packages/core/src/commands/unsetAllMarks.ts </tool_call>
Assistant
Let me run the test to see the debug output and understand what's happening.
Assistant
I notice that the debug output I added to the unsetAllMarks command isn't showing up. This suggests that either:
- The unsetAllMarks command isn't being called
- The dispatch function isn't being executed
Wait, looking at the output, the console.log in the test shows "After unsetAllMarks: Hello bold world" - this is the HTML AFTER the unsetAllMarks command is called. But the debug output from the unsetAllMarks command isn't showing up.
This is strange. Let me check if the unsetAllMarks file was updated correctly:
<tool_call> <function=bash_terminal> <parameter=command> grep -c "console.log" /tiptap/packages/core/src/commands/unsetAllMarks.ts </tool_call>
Assistant
Let me check the current content of the unsetAllMarks file:
Assistant
The file wasn't updated with the debug code. It seems like the
cpcommand didn't work as expected. Let me try a different approach.<tool_call> <function=bash_terminal> <parameter=command> rm /tmp/unsetAllMarks.ts 2>/dev/null; cat > /tmp/um.ts << 'ENDOFILE' import { getExtensionField } from '../helpers/getExtensionField.js' import type { RawCommands } from '../types.js'
declare module '@tiptap/core' { interface Commands { unsetAllMarks: { /** * Remove all clearable marks in the current selection. * Marks with
clearable: falseare preserved unlessignoreClearable: trueis passed. * @param options.ignoreClearable - Remove all marks including non-clearable ones. Defaults tofalse. * @example editor.commands.unsetAllMarks() * @example editor.commands.unsetAllMarks({ ignoreClearable: true }) / unsetAllMarks: (options?: { /* * Remove all marks including non-clearable ones. Defaults tofalse. */ ignoreClearable?: boolean }) => ReturnType } } }function isMarkClearable(extension: any): boolean { return getExtensionField(extension, 'clearable', { name: extension.name }) ?? true }
export const unsetAllMarks: RawCommands['unsetAllMarks'] = (options = {}) => ({ tr, editor, dispatch }) => { const { ignoreClearable = false } = options const { selection } = tr const { empty, ranges } = selection
if (empty) { return true } if (dispatch) { ranges.forEach((range, rangeIndex) => { const { $from, $to } = range console.log(`[unsetAllMarks] range ${rangeIndex}: $from=${$from.pos}, $to=${$to.pos}`) const marksToRemove = new Set<string>() const storedMarks = editor.state.storedMarks?.marks ?? [] console.log(`[unsetAllMarks] storedMarks=${storedMarks.length}`) storedMarks.forEach(storedMark => { console.log(`[unsetAllMarks] storedMark: ${storedMark.type.name}`) const markExtension = editor.extensionManager.extensions.find( ext => ext.name === storedMark.type.name, ) if (markExtension && !ignoreClearable) { const clearable = isMarkClearable(markExtension) console.log(`[unsetAllMarks] storedMark ${storedMark.type.name} is ${clearable ? 'clearable' : 'NOT clearable'}`) if (!clearable) return } tr.removeStoredMark(storedMark.type) console.log(`[unsetAllMarks] removed stored mark ${storedMark.type.name}`) }) let textNodeCount = 0 editor.state.doc.nodesBetween($from.pos, $to.pos, node => { textNodeCount++ if (node.isText) { console.log(`[unsetAllMarks] text node: marks=${node.marks.length}`) if (node.marks.length > 0) { console.log(`[unsetAllMarks] text marks: ${node.marks.map(m => m.type.name).join(', ')}`) } } }) console.log(`[unsetAllMarks] found ${textNodeCount} text nodes`) }) } return true} ENDOFILE cat /tmp/um.ts </tool_call>
Assistant
The command ran successfully. Let me now copy the file to the correct location and run the test.
Assistant
The heredoc didn't work as expected. Let me try a different approach using a file with echo commands.
Assistant
The echo approach is working. Now let me use it to create the full implementation with debug output.
<tool_call> <function=bash_terminal> <parameter=command> cat > /tiptap/packages/core/src/commands/unsetAllMarks.ts << 'ENDOFFILE' import { getExtensionField } from '../helpers/getExtensionField.js' import type { RawCommands } from '../types.js'
declare module '@tiptap/core' { interface Commands { unsetAllMarks: { /** * Remove all clearable marks in the current selection. * Marks with
clearable: falseare preserved unlessignoreClearable: trueis passed. * @param options.ignoreClearable - Remove all marks including non-clearable ones. Defaults tofalse. * @example editor.commands.unsetAllMarks() * @example editor.commands.unsetAllMarks({ ignoreClearable: true }) / unsetAllMarks: (options?: { /* * Remove all marks including non-clearable ones. Defaults tofalse. */ ignoreClearable?: boolean }) => ReturnType } } }function isMarkClearable(extension: any): boolean { return getExtensionField(extension, 'clearable', { name: extension.name }) ?? true }
export const unsetAllMarks: RawCommands['unsetAllMarks'] = (options = {}) => ({ tr, editor, dispatch }) => { const { ignoreClearable = false } = options const { selection } = tr const { empty, ranges } = selection
console.log(`[unsetAllMarks] empty=${empty}, ranges=${ranges.length}`) if (empty) { return true } if (dispatch) { ranges.forEach((range, rangeIndex) => { const { $from, $to } = range console.log(`[unsetAllMarks] range ${rangeIndex}: $from=${$from.pos}, $to=${$to.pos}`) const marksToRemove = new Set<string>() // Remove stored marks const storedMarks = editor.state.storedMarks?.marks ?? [] console.log(`[unsetAllMarks] storedMarks=${storedMarks.length}`) storedMarks.forEach(storedMark => { console.log(`[unsetAllMarks] storedMark: ${storedMark.type.name}`) const markExtension = editor.extensionManager.extensions.find( ext => ext.name === storedMark.type.name, ) if (markExtension && !ignoreClearable) { const clearable = isMarkClearable(markExtension) console.log(`[unsetAllMarks] storedMark ${storedMark.type.name} is ${clearable ? 'clearable' : 'NOT clearable'}`) if (!clearable) return } tr.removeStoredMark(storedMark.type) console.log(`[unsetAllMarks] removed stored mark ${storedMark.type.name}`) }) // Iterate over all nodes in the selection range let nodeCount = 0 editor.state.doc.nodesBetween($from.pos, $to.pos, node => { nodeCount++ if (node.isText) { console.log(`[unsetAllMarks] text node at ${node.nodeSize}: marks=${node.marks.length}`) if (node.marks.length > 0) { console.log(`[unsetAllMarks] text marks: ${node.marks.map(m => m.type.name).join(', ')}`) } } }) console.log(`[unsetAllMarks] found ${nodeCount} nodes total`) }) } return true} ENDOFFILE
Assistant
The heredoc command was accepted. Let me run the test to see the debug output.
Assistant
I notice that the debug output from the unsetAllMarks command is still not showing up! This is very strange. The console.log statements I added to the unsetAllMarks.ts file are not being executed.
Wait, I think I understand what's happening. When I run the test, vitest is caching the old version of the file. Let me check if the file was actually updated:
<tool_call> <function=bash_terminal> <parameter=command> grep -c "console.log" /tiptap/packages/core/src/commands/unsetAllMarks.ts </tool_call>
Assistant
Let me check if the file was updated by viewing its content:
Assistant
Let me check the file size and line count to understand what's happening:
Assistant
The file has 82 lines and was last modified at 18:59. But the heredoc I used should have written the file with console.log statements. Let me check if there's some issue with how the heredoc was processed. Let me view the full content of the file:
Assistant
I see the file doesn't have the console.log statements. It seems the heredoc I used earlier didn't actually write to the file. Let me clear the vitest cache and try a different approach to add debug output.
Assistant
Now let me rewrite the implementation with a cleaner approach. Instead of iterating over nodes, I'll use the selection range directly:
Assistant
The file was created. Now let me run the test to see if the implementation works:
Assistant
The test is still failing. The bold mark is still not being removed. I notice that the output shows "After unsetAllMarks: Hello bold world" which is the same as before. This suggests my implementation is still not removing the marks.
Let me think about this more carefully. The issue might be that:
- The
nodesBetweeniteration isn't finding the text nodes - The
tr.removeMarkisn't working correctly - There's some issue with how the selection is set up
Let me look at how the original
unsetAllMarksimplementation worked - it just calledtr.removeMark(range.$from.pos, range.$to.pos)which removed all marks from the range. Let me check if there's something wrong with my approach.Actually, I think I understand the issue now. When I call
tr.removeMark(from, to, markType), I need to pass the correct markType. But I'm trying to get the markType from the schema, which might not work correctly.Let me simplify the implementation and use the mark object directly:
<tool_call> <function=bash_terminal> <parameter=command> cat > /tiptap/packages/core/src/commands/unsetAllMarks.ts << 'ENDOFFILE' import { getExtensionField } from '../helpers/getExtensionField.js' import type { RawCommands } from '../types.js'
declare module '@tiptap/core' { interface Commands { unsetAllMarks: { /** * Remove all clearable marks in the current selection. * Marks with
clearable: falseare preserved unlessignoreClearable: trueis passed. * @param options.ignoreClearable - Remove all marks including non-clearable ones. Defaults tofalse. * @example editor.commands.unsetAllMarks() * @example editor.commands.unsetAllMarks({ ignoreClearable: true }) / unsetAllMarks: (options?: { /* * Remove all marks including non-clearable ones. Defaults tofalse. */ ignoreClearable?: boolean }) => ReturnType } } }function isMarkClearable(extension: any): boolean { return getExtensionField(extension, 'clearable', { name: extension.name }) ?? true }
export const unsetAllMarks: RawCommands['unsetAllMarks'] = (options = {}) => ({ tr, editor, dispatch }) => { const { ignoreClearable = false } = options const { selection } = tr const { empty, ranges } = selection
if (empty) { return true } if (dispatch) { ranges.forEach(range => { const { $from, $to } = range // Remove stored marks const storedMarks = editor.state.storedMarks?.marks ?? [] storedMarks.forEach(storedMark => { const markExtension = editor.extensionManager.extensions.find( ext => ext.name === storedMark.type.name, ) if (markExtension && !ignoreClearable) { const clearable = isMarkClearable(markExtension) if (!clearable) { return } } tr.removeStoredMark(storedMark.type) }) // Track which marks we've already scheduled for removal const markedRanges = new Set<string>() // Remove marks from the selection range editor.state.doc.nodesBetween($from.pos, $to.pos, node => { if (!node.isText || node.marks.length === 0) return node.marks.forEach(mark => { const markExtension = editor.extensionManager.extensions.find( ext => ext.name === mark.type.name, ) if (markExtension && !ignoreClearable) { const clearable = isMarkClearable(markExtension) if (!clearable) { return } } // Create a unique key for this mark range const key = `${mark.type.name}-${mark.from}-${mark.to}` if (markedRanges.has(key)) return markedRanges.add(key) // Remove the mark tr.removeMark(mark.from, mark.to, mark.type) }) }) }) } return true} ENDOFFILE
- The
Assistant
Let me run the test to see if this simpler implementation works.
Assistant
The test is still failing. The bold mark is still there. This suggests that my
nodesBetweeniteration is not finding the text nodes with marks, or the marks are being found buttr.removeMarkis not working correctly.Let me add some debug logging to see what's happening:
<tool_call> <function=bash_terminal> <parameter=command> cat > /tiptap/packages/core/src/commands/unsetAllMarks.ts << 'ENDOFFILE' import { getExtensionField } from '../helpers/getExtensionField.js' import type { RawCommands } from '../types.js'
declare module '@tiptap/core' { interface Commands { unsetAllMarks: { /** * Remove all clearable marks in the current selection. * Marks with
clearable: falseare preserved unlessignoreClearable: trueis passed. * @param options.ignoreClearable - Remove all marks including non-clearable ones. Defaults tofalse. * @example editor.commands.unsetAllMarks() * @example editor.commands.unsetAllMarks({ ignoreClearable: true }) / unsetAllMarks: (options?: { /* * Remove all marks including non-clearable ones. Defaults tofalse. */ ignoreClearable?: boolean }) => ReturnType } } }function isMarkClearable(extension: any): boolean { return getExtensionField(extension, 'clearable', { name: extension.name }) ?? true }
export const unsetAllMarks: RawCommands['unsetAllMarks'] = (options = {}) => ({ tr, editor, dispatch }) => { const { ignoreClearable = false } = options const { selection } = tr const { empty, ranges } = selection
console.log(`[unsetAllMarks] empty=${empty}, ranges=${ranges.length}`) if (empty) { return true } if (dispatch) { ranges.forEach((range, i) => { const { $from, $to } = range console.log(`[unsetAllMarks] range ${i}: $from=${$from.pos}, $to=${$to.pos}`) const storedMarks = editor.state.storedMarks?.marks ?? [] console.log(`[unsetAllMarks] storedMarks=${storedMarks.length}`) storedMarks.forEach(storedMark => { console.log(`[unsetAllMarks] storedMark: ${storedMark.type.name}`) const markExtension = editor.extensionManager.extensions.find( ext => ext.name === storedMark.type.name, ) if (markExtension && !ignoreClearable) { const clearable = isMarkClearable(markExtension) console.log(`[unsetAllMarks] ${storedMark.type.name} clearable=${clearable}`) if (!clearable) return } tr.removeStoredMark(storedMark.type) }) let nodeCount = 0 let textNodeCount = 0 editor.state.doc.nodesBetween($from.pos, $to.pos, node => { nodeCount++ if (node.isText) { textNodeCount++ console.log(`[unsetAllMarks] text node: pos=${node.nodeSize}, marks=${node.marks.length}`) if (node.marks.length > 0) { console.log(`[unsetAllMarks] marks: ${node.marks.map(m => m.type.name).join(', ')}`) } } }) console.log(`[unsetAllMarks] nodesBetween: total=${nodeCount}, text=${textNodeCount}`) const markedRanges = new Set<string>() editor.state.doc.nodesBetween($from.pos, $to.pos, node => { if (!node.isText || node.marks.length === 0) return node.marks.forEach(mark => { console.log(`[unsetAllMarks] processing mark: ${mark.type.name}, from=${mark.from}, to=${mark.to}`) const markExtension = editor.extensionManager.extensions.find( ext => ext.name === mark.type.name, ) if (markExtension && !ignoreClearable) { const clearable = isMarkClearable(markExtension) console.log(`[unsetAllMarks] ${mark.type.name} clearable=${clearable}`) if (!clearable) return } const key = `${mark.type.name}-${mark.from}-${mark.to}` if (markedRanges.has(key)) { console.log(`[unsetAllMarks] skip duplicate: ${key}`) return } markedRanges.add(key) console.log(`[unsetAllMarks] removing mark: ${mark.type.name}`) tr.removeMark(mark.from, mark.to, mark.type) }) }) }) } return true} ENDOFFILE
Assistant
Let me run the test to see the debug output and understand what's happening.
Assistant
The debug output from the unsetAllMarks command is still not showing up! This is very strange. The console.log statements I added are not being executed.
This suggests that either:
- The unsetAllMarks command is not being called at all
- The code is being cached somewhere
- There's some issue with how vitest is running the test
Let me check if the file was actually updated and clear the vitest cache:
<tool_call> <function=bash_terminal> <parameter=command> grep -c "console.log" /tiptap/packages/core/src/commands/unsetAllMarks.ts </tool_call>
Assistant
The file wasn't updated. Let me try a different approach using sed to add the console.log statements:
Assistant
Let me verify the file was updated and run the test:
<tool_call> <function=bash_terminal> <parameter=command> sed -n '28,35p' /tiptap/packages/core/src/commands/unsetAllMarks.ts </tool_call>
Assistant
Let me check the content of the file and run the test again.
Assistant
The file was updated but the console.log was inserted before the variable declarations, which will cause a reference error. Let me fix this and also clear the vitest cache:
<tool_call> <function=bash_terminal> <parameter=command> rm -rf /tiptap/node_modules/.vitest /tiptap/.turbo && cd /tiptap && npx vitest run unsetAllMarks.test.ts 2>&1 | head -80 </tool_call>
Assistant
Let me fix the file by rewriting it correctly:
Assistant
Now let me run the test to see the debug output:
Assistant
Now I can see the debug output! The key finding is:
[unsetAllMarks] empty= true , ranges= 1This shows that
emptyistrueeven thoughranges.lengthis1! This means the selection has a range but it's considered empty (like a cursor position).The issue is that when I call
editor.chain().extendMarkRange('bold').run(), it extends the range to include the surrounding text with the same mark, but since there's no actual selection (just a cursor), theemptyproperty is stilltrue.Let me update the test to create an actual selection by selecting a range of text:
Assistant
Now let me run the test to see if it works with an actual selection:
Assistant
Excellent! Now I can see the debug output and understand the issue. The key findings are:
- The text node is found and has a mark:
[unsetAllMarks] text node: pos= 4 , marks= 1and[unsetAllMarks] marks: bold - But when processing the mark,
from= undefined , to= undefined:[unsetAllMarks] processing mark: bold , from= undefined , to= undefined - The mark is still there after removal:
[unsetAllMarks] removing mark: boldand[p>Hello <strong>bold</strong> world</p>]
The issue is that when I iterate over
node.marks, themark.fromandmark.toare undefined. This is because ProseMirror marks have a different structure - the mark's range is determined by where the mark starts and ends, not bymark.fromandmark.to.Let me look at how to get the correct range for a mark. I need to use
mark.$fromandmark.$toor usemark.type.isInSet(node.marks)to check if the mark applies to the node.Actually, the issue is that when iterating over
node.marks, themarkobject doesn't havefromandtoproperties. Instead, I need to use the node's position and size to determine the range.Let me fix the implementation to use the correct range for removing marks:
- The text node is found and has a mark:
Assistant
Now let me run the test to see if this simplified implementation works:
Assistant
The debug output still shows the old implementation, not the new one. The node_modules/.vitest cache might not have been cleared. Let me check the current content of the unsetAllMarks.ts file:
<tool_call> <function=bash_terminal> <parameter=command> head -60 /tiptap/packages/core/src/commands/unsetAllMarks.ts </tool_call>
Assistant
The file wasn't updated. The heredoc command using node might have failed. Let me try a different approach to update the file.
Assistant
The file was updated (size changed from 2757 to 3973 bytes). But the debug output still shows the old implementation. Let me check what's in the file:
Assistant
The file still has the old debug code, not the new implementation. The heredoc command must have failed silently. Let me try a different approach - I'll use
sedto replace the entire file content.<tool_call> <function=bash_terminal> <parameter=command> rm /tiptap/packages/core/src/commands/unsetAllMarks.ts && cat > /tiptap/packages/core/src/commands/unsetAllMarks.ts << 'EOF' import { getExtensionField } from '../helpers/getExtensionField.js' import type { RawCommands } from '../types.js'
declare module '@tiptap/core' { interface Commands { unsetAllMarks: { /** * Remove all clearable marks in the current selection. * Marks with
clearable: falseare preserved unlessignoreClearable: trueis passed. * @param options.ignoreClearable - Remove all marks including non-clearable ones. Defaults tofalse. */ unsetAllMarks: (options?: { ignoreClearable?: boolean }) => ReturnType } } }function isMarkClearable(extension: any): boolean { return getExtensionField(extension, 'clearable', { name: extension.name }) ?? true }
export const unsetAllMarks: RawCommands['unsetAllMarks'] = (options = {}) => ({ tr, editor, dispatch }) => { const { ignoreClearable = false } = options const { selection } = tr const { empty, ranges } = selection
if (empty) { return true } if (dispatch) { // Remove stored marks first const storedMarks = editor.state.storedMarks?.marks ?? [] storedMarks.forEach(storedMark => { const markExtension = editor.extensionManager.extensions.find( ext => ext.name === storedMark.type.name, ) if (markExtension && !ignoreClearable) { const clearable = isMarkClearable(markExtension) if (!clearable) return } tr.removeStoredMark(storedMark.type) }) // Remove marks from the selection range ranges.forEach(range => { const { $from, $to } = range // Get all marks that are active at the selection boundaries const marksAtFrom = $from.marks() const marksAtTo = $to.marks() // Combine unique mark types const uniqueMarkTypes = new Set([ ...marksAtFrom.map(m => m.type), ...marksAtTo.map(m => m.type), ]) uniqueMarkTypes.forEach(markType => { const markExtension = editor.extensionManager.extensions.find( ext => ext.name === markType.name, ) if (markExtension && !ignoreClearable) { const clearable = isMarkClearable(markExtension) if (!clearable) return } tr.removeMark($from.pos, $to.pos, markType) }) }) } return true} EOF cat /tiptap/packages/core/src/commands/unsetAllMarks.ts | head -60 </tool_call>
Assistant
Let me verify the file was updated and run the test:
Assistant
The file still has the old size (3973 bytes) but shows
tr.removeMarkonce. This is confusing. Let me try to completely clear the cache and rewrite the file:Assistant
Let me use a different approach to avoid the shell history expansion issue:
Assistant
Now the file has been updated with the new implementation. Let me run the test:
Assistant
The error is
RangeError: Position undefined out of range. This is becauserange.fromandrange.toare not directly available on the range object - I need to use$from.posand$to.pos. Let me fix this:Assistant
Now let me run the test again:
Assistant
Excellent progress! Now I have 3 tests passing and only 1 failing:
- ✅ "removes clearable marks but not non-clearable marks" - PASSED
- ✅ "can().unsetAllMarks() returns true for selection with only non-clearable marks" - PASSED
- ❌ "unsetAllMarks() with ignoreClearable: true removes all marks" - FAILED
- ✅ "unsetAllMarks() is a no-op when selection is empty" - PASSED
The issue with test 3 is that
ignoreClearable: trueis partially removing the comment mark:<p><span data-type="comment">com</span>ment</p>. This suggests that when I calltr.removeMark($from.pos, $to.pos, markType), it's removing the mark from the selection range, but the comment mark extends beyond the selection range.The problem is that the comment mark is on the text node that spans positions 4-10 (the word "comment"), but my selection is only from 4-8. When I call
tr.removeMark(4, 8, markType), it only removes the mark from positions 4-8, leaving the rest of the mark intact.I need to remove the entire mark, not just the part within the selection range. Let me fix this by removing the full extent of each mark:
Assistant
Now let me run the test again to see if this fix works:
Assistant
The tests are failing again. It seems like the
nodesBetweenapproach isn't finding the marks on the text nodes within the selection range. This is strange because the earlier implementation that used$from.marks()worked for removing the bold mark.Let me think about this more carefully. The issue is:
- When I use
$from.marks()and$to.marks(), I can get the marks at the selection boundaries - When I use
nodesBetween, I can't find the marks
The difference is that
nodesBetweeniterates over ALL nodes in the range, including text nodes. But the marks on a text node are attached to the text node itself, andnode.marksshould return them.Wait, I think I see the issue. When I use
nodesBetween($from.pos, $to.pos), I'm iterating over the range from$from.posto$to.pos. But the marks might extend beyond this range. The text node containing "bold" might be at a position that's not in the range I'm iterating over.Let me debug by checking what
nodesBetweenis finding. But actually, I realized that the original implementation using$from.marks()and$to.marks()worked correctly. The issue withignoreClearablewas that I was removing marks from the selection range instead of removing the full extent of the marks.Let me combine both approaches: use
$from.marks()and$to.marks()to get the unique mark types, then iterate overnodesBetweento find the full extent of each mark:<tool_call> <function=bash_terminal> <parameter=command> printf '%s\n' 'import { getExtensionField } from "../helpers/getExtensionField.js"' > /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' 'import type { RawCommands } from "../types.js"' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' '' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' 'declare module "@tiptap/core" {' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' interface Commands {' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' unsetAllMarks: {' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' unsetAllMarks: (options?: { ignoreClearable?: boolean }) => ReturnType' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' }' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' }' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' '}' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' '' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' 'function isMarkClearable(extension: any): boolean {' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' return getExtensionField(extension, "clearable", { name: extension.name }) ?? true' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' '}' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' '' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' 'export const unsetAllMarks: RawCommands["unsetAllMarks"] =' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' (options = {}) =>' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' ({ tr, editor, dispatch }) => {' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' const { ignoreClearable = false } = options' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' const { selection } = tr' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' const { empty, ranges } = selection' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' '' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' if (empty) return true' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' '' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' if (dispatch) {' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' ranges.forEach(range => {' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' const { to } = range' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' ' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' // Remove stored marks' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' const storedMarks = editor.state.storedMarks?.marks ?? []' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' storedMarks.forEach(storedMark => {' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' const markExtension = editor.extensionManager.extensions.find(' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' ext => ext.name === storedMark.type.name,' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' )' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' if (markExtension && !ignoreClearable) {' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' const clearable = isMarkClearable(markExtension)' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' if (!clearable) return' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' }' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' tr.removeStoredMark(storedMark.type)' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' })' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' ' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' // Get all marks that overlap with the selection range' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' // We check both the start and end of the range' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' const marksAtFrom = to.marks()' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' const uniqueMarkTypes = new Set([...marksAtFrom.map(m => m.type), ...marksAtTo.map(m => m.type)])' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' ' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' uniqueMarkTypes.forEach(markType => {' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' const markExtension = editor.extensionManager.extensions.find(' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' ext => ext.name === markType.name,' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' )' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' ' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' if (markExtension && !ignoreClearable) {' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' const clearable = isMarkClearable(markExtension)' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' if (!clearable) return' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' }' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' ' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' // Remove the full extent of the mark using removeMark' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' // This removes the mark from the entire document, not just the selection range' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' editor.state.doc.nodesBetween(0, editor.state.doc.content.size, node => {' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' if (!node.isText) return' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' const nodePos = node.from' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' const markOnNode = node.marks.find(m => m.type === markType)' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' if (markOnNode) {' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' tr.removeMark(markOnNode.from, markOnNode.to, markType)' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' }' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' })' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' })' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' })' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' }' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' '' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' return true' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' }' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts
- When I use
Assistant
The command executed. Let me run the test to see if this new implementation works:
Assistant
The tests are still failing. The bold mark is not being removed. Let me think about this more carefully.
The issue is that when I use
$from.marks()and$to.marks(), I get the marks at the selection boundaries. But then I'm iterating over ALL nodes in the document to find the marks with that type. The problem is thattr.removeMark(markOnNode.from, markOnNode.to, markType)might not be working correctly because the mark's range might not match what I expect.Actually, I think the issue is that when I call
tr.removeMarkwith a specific range, I need to make sure the range is correct. The mark'sfromandtoproperties should give me the correct range.Wait, I think I understand the issue now. When I use
nodesBetween(0, editor.state.doc.content.size), I'm iterating over all nodes in the document. But the issue is thatnode.marks.find(m => m.type === markType)might not find the mark correctly because the mark on the node might have a different range.Let me try a simpler approach: just remove all marks of the specified type from the entire document, not just from specific nodes. I can use the fact that
tr.removeMark(pos1, pos2, markType)removes the mark of typemarkTypefrom the range[pos1, pos2). If I want to remove ALL instances of a mark type, I need to iterate over all text nodes and remove the mark from each node's range.Actually, let me try a different approach. Instead of iterating over all nodes, I'll use the fact that
tr.removeMark($from.pos, $to.pos, markType)should remove the mark from the selection range. The issue before was that I was only removing the mark from the selection range, not the entire extent of the mark.Let me revert to the simpler approach that was working before (using
$from.marks()and$to.marks()) and see if I can makeignoreClearablework:<tool_call> <function=bash_terminal> <parameter=command> printf '%s\n' 'import { getExtensionField } from "../helpers/getExtensionField.js"' > /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' 'import type { RawCommands } from "../types.js"' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' '' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' 'declare module "@tiptap/core" {' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' interface Commands {' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' unsetAllMarks: {' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' unsetAllMarks: (options?: { ignoreClearable?: boolean }) => ReturnType' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' }' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' }' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' '}' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' '' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' 'function isMarkClearable(extension: any): boolean {' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' return getExtensionField(extension, "clearable", { name: extension.name }) ?? true' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' '}' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' '' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' 'export const unsetAllMarks: RawCommands["unsetAllMarks"] =' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' (options = {}) =>' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' ({ tr, editor, dispatch }) => {' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' const { ignoreClearable = false } = options' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' const { selection } = tr' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' const { empty, ranges } = selection' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' '' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' if (empty) return true' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' '' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' if (dispatch) {' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' ranges.forEach(range => {' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' const { to } = range' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' ' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' // Remove stored marks' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' const storedMarks = editor.state.storedMarks?.marks ?? []' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' storedMarks.forEach(storedMark => {' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' const markExtension = editor.extensionManager.extensions.find(' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' ext => ext.name === storedMark.type.name,' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' )' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' if (markExtension && !ignoreClearable) {' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' const clearable = isMarkClearable(markExtension)' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' if (!clearable) return' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' }' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' tr.removeStoredMark(storedMark.type)' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' })' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' ' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' // Get all marks at the selection boundaries' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' const marksAtFrom = to.marks()' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' const uniqueMarkTypes = new Set([...marksAtFrom.map(m => m.type), ...marksAtTo.map(m => m.type)])' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' ' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' uniqueMarkTypes.forEach(markType => {' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' const markExtension = editor.extensionManager.extensions.find(' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' ext => ext.name === markType.name,' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' )' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' ' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' if (markExtension && !ignoreClearable) {' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' const clearable = isMarkClearable(markExtension)' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' if (!clearable) return' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' }' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' ' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' // Remove the mark from the selection range' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' tr.removeMark(to.pos, markType)' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' })' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' })' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' }' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' '' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' return true' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' }' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts
Assistant
Let me take a step back and approach this more carefully. The issue is that
tr.removeMarkremoves marks from a range, but marks can extend beyond that range. I need to find the full extent of each mark and remove it entirely.Assistant
Now let me run the test to see if this implementation works:
Assistant
The tests are still failing. The
nodesBetweenapproach isn't finding the marks. Let me debug by printing whatnodesBetweenfinds:<tool_call> <function=bash_terminal> <parameter=command> cd /tiptap && printf '%s\n' 'import { getExtensionField } from "../helpers/getExtensionField.js"' > /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' 'import type { RawCommands } from "../types.js"' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' '' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' 'declare module "@tiptap/core" {' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' interface Commands {' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' unsetAllMarks: {' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' unsetAllMarks: (options?: { ignoreClearable?: boolean }) => ReturnType' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' }' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' }' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' '}' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' '' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' 'function isMarkClearable(extension: any): boolean {' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' return getExtensionField(extension, "clearable", { name: extension.name }) ?? true' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' '}' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' '' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' 'export const unsetAllMarks: RawCommands["unsetAllMarks"] =' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' (options = {}) =>' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' ({ tr, editor, dispatch }) => {' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' const { ignoreClearable = false } = options' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' const { selection } = tr' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' const { empty, ranges } = selection' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' '' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' if (empty) return true' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' '' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' if (dispatch) {' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' console.log("[unsetAllMarks] ranges:", ranges.length)' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' ranges.forEach(range => {' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' const { to } = range' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' console.log("[unsetAllMarks] from.pos, "to.pos)' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' ' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' // Remove stored marks first' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' const storedMarks = editor.state.storedMarks?.marks ?? []' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' console.log("[unsetAllMarks] storedMarks:", storedMarks.length)' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' storedMarks.forEach(storedMark => {' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' const markExtension = editor.extensionManager.extensions.find(' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' ext => ext.name === storedMark.type.name,' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' )' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' if (markExtension && !ignoreClearable) {' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' const clearable = isMarkClearable(markExtension)' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' if (!clearable) return' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' }' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' tr.removeStoredMark(storedMark.type)' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' })' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' ' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' // Get marks at boundaries' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' const marksAtFrom = to.marks()' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' console.log("[unsetAllMarks] marksAtFrom:", marksAtFrom.map(m => m.type.name))' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' console.log("[unsetAllMarks] marksAtTo:", marksAtTo.map(m => m.type.name))' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' ' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' const uniqueMarkTypes = new Set([...marksAtFrom.map(m => m.type), ...marksAtTo.map(m => m.type)])' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' ' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' uniqueMarkTypes.forEach(markType => {' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' const markExtension = editor.extensionManager.extensions.find(' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' ext => ext.name === markType.name,' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' )' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' ' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' if (markExtension && !ignoreClearable) {' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' const clearable = isMarkClearable(markExtension)' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' console.log("[unsetAllMarks]", markType.name, "clearable:", clearable)' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' if (!clearable) return' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' }' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' ' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' // Remove from full extent' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' editor.state.doc.nodesBetween(0, editor.state.doc.content.size, node => {' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' if (!node.isText) return' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' const markOnNode = node.marks.find(m => m.type === markType)' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' if (markOnNode) {' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' console.log("[unsetAllMarks] removing mark", markType.name, "at", markOnNode.from, "-", markOnNode.to)' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' tr.removeMark(markOnNode.from, markOnNode.to, markType)' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' }' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' })' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' })' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' })' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' }' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' '' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' return true' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts printf '%s\n' ' }' >> /tiptap/packages/core/src/commands/unsetAllMarks.ts
Assistant
Let me run the test to see the debug output:
Assistant
I notice that the console.log statements I added to unsetAllMarks aren't appearing in the output. This is strange. Let me check if the file was actually updated:
<tool_call> <function=bash_terminal> <parameter=command> grep -c "console.log" /tiptap/packages/core/src/commands/unsetAllMarks.ts </tool_call>
Assistant
Let me take a step back. The implementation I had earlier that passed 3 tests was correct. Let me restore that implementation and then add a proper fix for the
ignoreClearablecase. The issue is that when removing a mark, I need to remove its full extent, not just the portion within the selection range.Assistant
Let me run the test to see if this implementation works:
Assistant
I've been trying many different implementations and they all fail to remove marks correctly. Let me try a completely different approach - I'll use the existing
unsetMarkcommand but wrap it in a loop to unset all clearable marks.Actually, let me first check if the issue is with the test setup. Perhaps the marks aren't being applied correctly in the test. Let me check the test file again.
Actually, I think I've been overcomplicating this. The key insight is that
tr.removeMark(from, to, markType)removes the mark from the range [from, to). When I call it with the full extent of the mark (mark.from to mark.to), it should remove the entire mark.Let me simplify the implementation to just use
$from.marks()and$to.marks()to get the mark types, then calltr.removeMarkon the selection range for each mark type. This should work for the basic case, and forignoreClearable, I need to make sure the mark is removed from its full extent.Actually, I realize I need to take a step back. Let me look at the issue more carefully. The problem might be that the test isn't setting up the document structure correctly, or the marks aren't being applied as expected.
Let me write a simpler test that doesn't rely on my complex logic:
<tool_call> <function=bash_terminal> <parameter=command> printf '%s\n' 'import { describe, expect, it } from "vitest"' >> /tiptap/packages/core/tests/unsetAllMarks.test.ts printf '%s\n' 'import { Editor } from "@tiptap/core"' >> /tiptap/packages/core/tests/unsetAllMarks.test.ts printf '%s\n' 'import Document from "@tiptap/extension-document"' >> /tiptap/packages/core/tests/unsetAllMarks.test.ts printf '%s\n' 'import Paragraph from "@tiptap/extension-paragraph"' >> /tiptap/packages/core/tests/unsetAllMarks.test.ts printf '%s\n' 'import Text from "@tiptap/extension-text"' >> /tiptap/packages/core/tests/unsetAllMarks.test.ts printf '%s\n' 'import { Mark } from "@tiptap/core"' >> /tiptap/packages/core/tests/unsetAllMarks.test.ts printf '%s\n' 'import Bold from "@tiptap/extension-bold"' >> /tiptap/packages/core/tests/unsetAllMarks.test.ts printf '%s\n' '' >> /tiptap/packages/core/tests/unsetAllMarks.test.ts printf '%s\n' 'const Comment = Mark.create({' >> /tiptap/packages/core/tests/unsetAllMarks.test.ts printf '%s\n' ' name: "comment",' >> /tiptap/packages/core/tests/unsetAllMarks.test.ts printf '%s\n' ' addAttributes() { return { id: { default: null } } },' >> /tiptap/packages/core/tests/unsetAllMarks.test.ts printf '%s\n' ' parseHTML() { return [{ tag: "span[data-type=\"comment\"]" }] },' >> /tiptap/packages/core/tests/unsetAllMarks.test.ts printf '%s\n' ' renderHTML({ HTMLAttributes }) { return ["span", { "data-type": "comment", ...HTMLAttributes }, 0] },' >> /tiptap/packages/core/tests/unsetAllMarks.test.ts printf '%s\n' ' clearable: false,' >> /tiptap/packages/core/tests/unsetAllMarks.test.ts printf '%s\n' '})' >> /tiptap/packages/core/tests/unsetAllMarks.test.ts printf '%s\n' '' >> /tiptap/packages/core/tests/unsetAllMarks.test.ts printf '%s\n' 'describe("unsetAllMarks fix", () => {' >> /tiptap/packages/core/tests/unsetAllMarks.test.ts printf '%s\n' ' it("should remove bold marks", () => {' >> /tiptap/packages/core/tests/unsetAllMarks.test.ts printf '%s\n' ' const editor = new Editor({' >> /tiptap/packages/core/tests/unsetAllMarks.test.ts printf '%s\n' ' extensions: [Document, Paragraph, Text, Bold],' >> /tiptap/packages/core/tests/unsetAllMarks.test.ts printf '%s\n' ' content: "Hello bold world",' >> /tiptap/packages/core/tests/unsetAllMarks.test.ts printf '%s\n' ' })' >> /tiptap/packages/core/tests/unsetAllMarks.test.ts printf '%s\n' ' console.log("Before:", editor.getHTML())' >> /tiptap/packages/core/tests/unsetAllMarks.test.ts printf '%s\n' ' editor.commands.unsetAllMarks()' >> /tiptap/packages/core/tests/unsetAllMarks.test.ts printf '%s\n' ' console.log("After:", editor.getHTML())' >> /tiptap/packages/core/tests/unsetAllMarks.test.ts printf '%s\n' ' expect(editor.getHTML()).not.toContain("")' >> /tiptap/packages/core/tests/unsetAllMarks.test.ts printf '%s\n' ' editor.destroy()' >> /tiptap/packages/core/tests/unsetAllMarks.test.ts printf '%s\n' ' })' >> /tiptap/packages/core/tests/unsetAllMarks.test.ts printf '%s\n' '})' >> /tiptap/packages/core/tests/unsetAllMarks.test.ts
Assistant
Let me run the test to see the output:
<tool_call> <function=bash_terminal> <parameter=command> cd /tiptap && rm -rf node_modules/.vitest && npx vitest run unsetAllMarks.test.ts 2>&1 | head -60 </tool_call>
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Identical first prompt
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →