ISSUE DESCRIPTION [PRO]: unsetAllMarks deletes comments Affected Packages…
- User
ISSUE DESCRIPTION
[PRO]: unsetAllMarks deletes comments
Affected Packages
extension-comments
Version(s)
2.17.5
Description of the Bug
Our Tiptap editor has a "clear formatting" button that calls
unsetAllMarksto remove formatting from the selection.We noticed, however, that if the selection includes content associated with a comment, the comment is also deleted (presumably because the
<span>element wrapping the content is removed).Is this a bug? I can see how we might want
unsetAllMarksto include comments, if we consider the comment tag a "mark," but at the same time I imagine users would generally not expectunsetAllMarksto delete comments.For now, as a workaround, we are calling
unsetMarkseparately for all non-comment marks, e.g.editor.chain().focus().unsetMark('link').unsetMark('bold').unsetMark('strike') ...... but would be nice to be able to use
unsetAllMarksagain for formatting-specific marks. Thanks!Browser Used
Chrome
Code Example (Preferred)
No response
Expected Behavior
unsetAllMarkswill remove formatting marks (listed here) but not remove comment tags or comments.Additional Context (Optional)
No response
Dependency Updates
- Yes, I've updated all my dependencies.
Evaluation contract
Marks are clearable by default. A mark configured with
clearable: falsemust surviveunsetAllMarks(), whileunsetAllMarks({ignoreClearable: true})removes it. Callingcan().unsetAllMarks()on a selection containing only non-clearable marks is a successful no-op and must returntrue; explicitly callingunsetMarkmay still remove a non-clearable mark.Interface
Type: Mark configuration option Name: MarkConfig.clearable Path: packages/core/src/Mark.ts Type: boolean | (() => boolean) Default: true Description: Controls whether unsetAllMarks removes this mark. Set false for semantic marks such as comments that must survive clear-formatting operations.
Assistant
Let me start by understanding the repository structure and the issue. The issue is about
unsetAllMarksdeleting comments. The fix should:- Add a
clearableoption toMarkConfig(inpackages/core/src/Mark.ts) - Modify
unsetAllMarkscommand (inpackages/core/src/commands/unsetAllMarks.ts) to respect theclearableoption - Set
clearable: falsefor the comments extension
Let me explore the repository structure first.
- Add a
Assistant
Let me look at the relevant files first: Mark.ts and unsetAllMarks.ts in packages/core/src/.
Assistant
Let me look at the key files: Mark.ts and unsetAllMarks.ts.
Assistant
I need to make just one tool call at a time.
Assistant
Now let me see the unsetAllMarks.ts:
Assistant
Now let me find the comments extension to understand how it's structured
Assistant
The comments extension might be in the packages directory. Let me look for it more specifically:
Assistant
Let me look at all packages:
Assistant
There doesn't seem to be a comment extension in the repo, but the fix is about the core package. Let me also look at the types and understand how
tr.removeMarkworks:Assistant
Let me look at how marks/extensions are accessed from the editor and the types
Assistant
Good,
clearabledoesn't exist yet. Let me look at the Extendable base class:Assistant
Let me look at the RawCommands type and how commands access the editor
Assistant
Let me look at the RawCommands type definition:
Assistant
Let me look at the UnionCommands type:
Assistant
Let me look at how the Command type is defined and what parameters commands receive:
Assistant
Let me look at CommandProps:
Assistant
Let me understand how the editor stores extensions and how to look up marks
Assistant
Let me look at the ExtensionManager to understand how to access mark configurations
Assistant
Let me look at how
getExtensionFieldworks and howcallOrReturnis used:Assistant
Let me check how marks are resolved by name from the editor:
Assistant
Let me look at how the editor and extension manager can look up an extension by type name:
Assistant
Let me look at more of the ExtensionManager, especially how it handles extensions vs. mark-types:
Assistant
Let me look at
splitExtensionsto understand how extensions are categorized:Assistant
Let me look at
splitExtensions:Assistant
Let me look at how the editor's
extensionManagerstores extensions, to understand how to look up a mark extension by name:Assistant
Let me check if there are existing tests for unsetAllMarks:
Assistant
Let me look at
unsetMarkcommand for reference on how to remove specific marksAssistant
Let me look at
getMarksBetweenhelper:Assistant
Now I have a good understanding of the codebase. Let me implement the changes. First, let me add the
clearableoption to `MarkAssistant
I need to use
bash_terminalwith theopencommand.Assistant
Let me scroll down to see the rest of the Mark.ts file
Assistant
Now let me check if there are core tests I can run:
Assistant
Now let me add the
clearableoption to theMarkConfiginterface. I'll add it after thecodeAssistant
Good. Now let me update the
unsetAllMarkscommand. Let me open itAssistant
Now let me rewrite the unsetAllMarks command:
Assistant
Let me check if the project can build/type-check. First, let me see if there's a build/test setup
Assistant
Let me check if there's TypeScript compilation or type checking I can run:
Assistant
Let me find the tsconfig files:
Assistant
Let me try type-checking with the main tsconfig:
Assistant
The errors are all pre-existing in demos and node_modules. Let me try building just the core package:
Assistant
Let me look at how existing tests are structured to write a quick verification:
Assistant
Let me check how tests are run for the core package:
Assistant
Let me create a temporary test script to verify the changes work:
Assistant
Let me try to run the existing tests to see if they pass, and also try a different approach to test:
Assistant
Good, the existing tests pass. Let me try building the core package first to resolve module paths, then test:
Assistant
Build succeeded. Now let me try running the test again:
Assistant
ProseMirror needs a DOM. Let me use vitest instead. Let me create a temporary test file that uses vitest:
Assistant
Let me temporarily put the test in the core tests directory:
Assistant
Now run the test:
Assistant
All 4 tests pass! Let me clean up the temporary test file and run the existing core tests to make sure nothing is broken
Assistant
Now let me run all existing core tests to make sure nothing is
Assistant
All 377 existing tests pass. Let me also check if there are any other tests in the monorepo that might be affected by running a broader test suite. Let me also check if the extension-link or other extensions have their own test that might be affected:
Assistant
All tests pass. Let me verify the final state of both modified files:
Assistant
I notice the formatting could be improved - there should be a blank line between the
clearableproperty and theparseHTMLcomment. Let me fix:Assistant
Let me fix the formatting with a different approach:
Assistant
Let me use sed to fix the formatting:
Assistant
Let me verify the fix:
Assistant
Good. Now let me view the final state of the unsetAllMarks file:
Assistant
Let me verify all tests still pass after the formatting fix:
Assistant
All tests pass. Let me see the git diff to review all changes:
Assistant
Let me rebuild the core package to make sure the build works with the changes:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.