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
I'll start by exploring the repository structure to understand the codebase and then find the relevant files to modify.
Assistant
I'll start by exploring the repository structure to understand the codebase.
Assistant
Now let me look at the existing tests for
unsetAllMarksand the comments extension to understand the patterns used.Assistant
There's no comments extension in this repo. The comments extension is part of Tiptap's pro/enterprise offering. Let me focus on the core changes needed. Let me look at the existing tests for
unsetAllMarksand understand the command structure better.Assistant
Let me look at the
can.spec.tsto understand how commands andcan()are tested, and how marks are configured in tests.Assistant
Now let me understand how the command gets access to the schema/mark types. Let me look at how other commands access extension state, like
toggleMarkand the structure of commands.Assistant
Now I understand the command structure. Let me look at how to access extension configuration/marks from within a command. Let me look at how the editor stores extensions and how to get the
clearableconfig. Let me look at theExtendableclass and how config is stored.Assistant
Now I understand how config is stored. The
clearableconfig will be available on the extension's config. Let me look at how the command receives the editor and how I can access extensions from within a command. Let me look at the command props type.Assistant
Now I understand the command structure. The command receives
editorwhich has the extension manager. Let me look at how to access extensions from the editor and how mark types relate to extensions.Assistant
Let me look at how
keepOnSplit(a similarboolean | (() => boolean)config) is resolved/used, to follow the existing patterns.Assistant
Let me look at
getExtensionFieldandcallOrReturnto understand how to resolve config values with proper context.Assistant
Let me look at the helpers directory structure to understand where to place a helper.
Assistant
Let me look at how
getMarkTypeandisMarkActiveare implemented, and how they access extensions.Assistant
Let me look at
splitExtensionsandgetSchemaTypeByNameto understand the extension-to-mark-type mapping.Assistant
Let me look at the imports in ExtensionManager to understand the types used for context building.
Assistant
Now I have a good understanding. Let me implement the solution. First, let me add the
clearableconfig option toMarkConfiginMark.ts.Assistant
Now let me add the
clearableoption afterkeepOnSplit:Assistant
Now let me create the helper function
isMarkClearable. Let me first check howgetMarkAttributesaccesses extensions to follow the same pattern.Assistant
Let me check if any existing helpers import from
../Mark.jsor../index.jsto understand circular dependency patterns.Assistant
Good. So importing
Editortype from../Editor.jsis fine in helpers. Now let me look at howgetSchemaByResolvedExtensionsaccesses extensions and the context, to follow the same pattern for resolvingclearable.Let me look at how
getExtensionFieldis called with context ingetSchemaByResolvedExtensions.ts.Assistant
Let me check the imports in
getExtensionField.tsto follow the same import pattern for types.Assistant
Now let me create the helper
isMarkClearable.ts:Assistant
Now let me add the export to the helpers index:
Assistant
Now let me modify the
unsetAllMarkscommand to respect theclearableconfig:Assistant
Let me check how
setMarkand other commands usetrvsstateto ensure I follow the right pattern for getting the schema.Assistant
The implementation follows the same pattern as
setMark(reading selection fromtr, schema fromstate). Now let me create a test script to verify the behavior. Let me first check the test setup and what's available.Assistant
Now let me create a temporary test script to verify the behavior. I'll create a custom non-clearable mark (simulating comments) and test the scenarios.
Assistant
The comment mark is preserved (the
<span>remains), but thedata-commentattribute is lost because I didn't register it as a mark attribute. This is a test setup issue. Let me fix the test mark to register the attribute properly so the test is accurate.Assistant
All 5 tests pass. Now let me verify the
unsetMarkstill removes non-clearable marks (per the contract: "explicitly calling unsetMark may still remove a non-clearable mark"). Let me add a quick test for that to be thorough.Assistant
All tests pass, including the verification that
unsetMarkstill removes non-clearable marks explicitly. Now let me run the existing core tests to make sure I didn't break anything.Assistant
All existing tests pass. Now let me check if there are any other places in the codebase that call
unsetAllMarksto ensure my signature change is backward-compatible.Assistant
All call sites use
unsetAllMarks()without arguments, so the optionaloptionsparameter is backward-compatible. Let me check theIsolatingCleardemo to understand an edge case that might be relevant.Assistant
The demo uses standard formatting marks (all clearable by default), so my change is backward-compatible. Let me optimize the command to compute the clearable mark types once before iterating over ranges, for better efficiency.
Assistant
All tests pass. Now let me run TypeScript type-checking to ensure my changes are type-correct.
Assistant
No type errors related to my changes. Let me check the overall tsc output to make sure I haven't introduced any errors.
Assistant
These errors are all pre-existing in the
demos/directory (about React menus, JSX runtime, ref types) and unrelated to my changes. Let me verify there are no errors specifically in thepackages/core/srcfiles.Assistant
These errors are all in the pre-existing
transformPastedHTML.test.tsfile, unrelated to my changes. Let me confirm my specific files have no errors by stashing my changes and comparing.Assistant
The original code (with stash) has 21 errors in
packages/core/src. Let me check how many errors my changes add.Assistant
The error count went from 21 to 20 (actually fewer), so my changes don't introduce new type errors. Let me directly verify none of my modified files appear in the error list.
Assistant
No type errors in any of my modified files. Now let me run the broader test suite for mark-related extensions to ensure backward compatibility.
Assistant
All mark-related extension tests pass. Now let me add a changeset, since this repo uses changesets for versioning. Let me check the changeset format.
Assistant
The implementation is complete and working. Let me refine the helper to include the
typein the context for consistency with howkeepOnSplit(the most similar option) is resolved inExtensionManager.setupExtensions.Assistant
All tests pass and no type errors. Now let me run the full core test suite one final time, then clean up the temporary test file.
Assistant
All 416 tests pass. Now let me remove the temporary test file since I should not add new tests to the repository.
Assistant
Now let me review the final diff of all my changes to make sure everything is clean.
Assistant
The diff is clean and complete. Let me run the core test suite one final time (without the temp test file) to confirm everything still passes.
Assistant
All 410 original tests pass. Let me run the linter to make sure my code follows the repo's style conventions.
Assistant
Both linting and formatting pass. Let me do one final check to ensure there are no comment-like extensions anywhere in the repo that might need the
clearable: falsesetting.Assistant
No comment extensions exist in this repo (it's a pro/enterprise extension). My core change enables it and any semantic mark to opt out of
unsetAllMarksby settingclearable: false. Let me do a final review of all the modified files.Assistant
Everything looks complete and correct. Let me do a final git status check to confirm only the intended files are changed and the temp test file is gone.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.