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 explore the repository structure to understand the codebase.
Assistant
Now I understand the structure. Let me look at how
can()works. ThecreateCanmethod setsdispatch = false(well, dispatch: undefined). So whencan().unsetAllMarks()is called, dispatch is undefined, meaning the command runs but doesn't dispatch. The command returnstrueif it can do the operation.Now let me understand the issue. I need to:
- Add a
clearableoption toMarkConfiginMark.ts. - Modify
unsetAllMarksto respect theclearableoption - by default, marks are clearable (true). Ifclearable: false, the mark is preserved unlessignoreClearable: trueis passed. can().unsetAllMarks()should returntruewhen selection contains only non-clearable marks (this is a successful no-op).
Let me look at how marks are accessed in the command. The command has access to
tr,dispatch. I need to access the mark types and their clearable config.Let me look at how other commands access extension fields or mark types.
- Add a
Assistant
Now let me look at how the command props are built and what's available (especially the editor / extension manager) so I can access mark configs:
Assistant
The command props include
editor. I can accesseditor.extensionManagerto get the mark extensions and theirclearableconfig. Let me look at howexitableis accessed in ExtensionManager:Assistant
Now let me look at how the ExtensionManager stores marks and how I can access mark extensions:
Assistant
Let me look at the comments extension to understand how it's structured:
Assistant
There's no extension-comments package in this repo. The issue is about adding a
clearableconfig option to core Mark and makingunsetAllMarksrespect it. Let me look at existing tests forunsetAllMarks:Assistant
Let me check the
CommandPropstype and how the editor gives access to extensions:Assistant
Now I have all the information I need. Let me look at how
removeMarkis used and theRawCommandstype to understand command signatures:Assistant
Let me check
callOrReturnand how extensions are stored:Assistant
Let me check the Editor class to confirm
extensionManagerandextensionStorageare accessible:Assistant
Let me check the Extension type to understand
extension.type,extension.name,extension.options:Assistant
Let me look at how the mark schema name relates to the extension name:
Assistant
Now I have a complete understanding. Let me implement the changes. First, add the
clearableoption toMarkConfiginMark.ts:Assistant
Now let me add the
clearableoption toMarkConfigafterexitable:Assistant
Now let me modify the
unsetAllMarks.tscommand to respect theclearableoption:Assistant
Let me verify the exports and check the build/types compile:
Assistant
Let me look at how existing tests set up an editor to test commands:
Assistant
Let me check the test setup for jsdom and how tests are run:
Assistant
Now let me write a temporary test to verify the implementation. First let me check extension-bold's exports:
Assistant
Now let me create a temporary test to verify my implementation:
Assistant
Let me fix the test file to be cleaner:
Assistant
All 4 tests pass. Let me add edge case tests - overlapping marks,
clearableas a function, and verifyunsetMarkstill removes non-clearable marks:Assistant
The "clearable as a function" test failed only due to my test's attribute setup (an unregistered attribute gets dropped). The function-based
clearable: () => falseactually works — the span survived. Let me fix the test assertion:Assistant
The result is inconsistent — let me rewrite the function test case more cleanly with a properly registered attribute:
Assistant
All 7 tests pass. Now let me run the linter and formatter on the changed files:
Assistant
There's a formatting issue in
unsetAllMarks.ts. Let me fix it:Assistant
Good, the formatter fixed the long line by breaking it. Now let me verify the format check passes again.
Assistant
Now let me re-run my test to confirm everything still passes after formatting:
Assistant
All tests pass. Now let me run the broader core test suite to make sure nothing is broken:
Assistant
All 417 tests pass. Let me check if there's a TypeScript typecheck to run, since vitest with esbuild doesn't do full type checking:
Assistant
Let me run a TypeScript typecheck on the core package to make sure types compile:
Assistant
No type errors in my changed files. Let me verify there are no type errors introduced in the core source overall:
Assistant
These errors are all in
transformPastedHTML.test.ts, a pre-existing test file I didn't touch. Let me confirm they're pre-existing by stashing my changes:Assistant
The 20 errors in
transformPastedHTML.test.tsare pre-existing (exist on clean repo). Let me confirm my changed files introduce no new errors by comparing total error counts:Assistant
With my changes: 373 errors. Clean: 376 errors. My changes introduce no new type errors (the difference is because my temp test file's
unsetAllMarks({ ignoreClearable: true })call is a type error against the old signature, but valid with my new signature). Let me confirm my changed source files have zero errors:Assistant
No errors in my source files. Let me check the demo file that references
unsetAllMarksto ensure my signature change is compatible:Assistant
The demo uses
unsetAllMarks()with no arguments, which is still valid since the options parameter is optional. No breaking change.Now let me clean up by removing my temporary test file (per instructions, I shouldn't add new tests to the repository):
Assistant
Now let me do a final review of my complete changes:
Assistant
The diff looks complete and correct. Let me run the full core test suite one final time (without the temp test file) to confirm nothing is broken:
Assistant
All 410 tests pass. Let me do a final lint and format check on both changed files:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.