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 first inspect the core mark configuration and command implementation, then locate relevant command tests and the comments extension to determine whether it should opt out explicitly. After reproducing the current behavior in the existing test framework, I’ll implement the option and command semantics, run focused tests and type checks, and review the diff.
- Assistant
The command currently calls ProseMirror’s untyped
removeMark(from, to), confirming that every mark is removed. The new behavior needs access to each Tiptap mark extension’s resolvedclearableconfiguration, so I’ll inspect how command contexts expose the editor/extension manager and how similar extension-level flags are resolved. - Assistant
There is no open-source
extension-commentspackage in this checkout, so the core interface is the intended integration point; comments can configure themselves withclearable: false. I’ll now inspect command context types, extension manager access patterns, and test layout while excluding vendorednode_modulesnoise. - Assistant
The command context likely already includes
editor; I’ll verify its exact definition and inspect representative tests for editor setup and selection assertions. Then I can add a focused temporary reproduction without modifying repository tests, as required. - Assistant
I need the omitted type lines and extension manager public fields. The implementation should resolve inherited/function-valued configuration exactly like other mark fields, default missing values to
true, remove each clearable mark type individually, and preservecan()as a successful no-op because the command unconditionally returns true. - Assistant
Before changing source, I’ll create and immediately remove a temporary Vitest reproduction. It defines a semantic mark using a cast (because
clearableis not yet typed), selects text carrying both semantic and bold marks, and demonstrates that todayunsetAllMarks()removes both. - Assistant
The first test invocation was blocked by Corepack’s interactive package-manager download prompt (and timed out), not by the test. I’ll bypass Corepack using the already-installed root Vitest binary, capture the expected baseline failure, and ensure the temporary file is removed afterward.
- Assistant
The baseline reproduction failed exactly because all marks disappeared. I’ll now add the public
MarkConfig.clearableoption and updateunsetAllMarksto acceptignoreClearable. In normal mode it will resolve each mark extension’s inherited/static/function-valued option and remove only types whose value is notfalse; override mode retains the prior remove-everything operation. Resolution stays inside the dispatch branch socan().unsetAllMarks()remains a side-effect-free successful no-op. - Assistant
The insertion targeted the opening line of the next JSDoc and accidentally removed its
/**, which the formatter correctly caught. I’ll repair that local block, rerun formatting, and then run TypeScript/build validation to catch any type narrowing or command declaration issues. - Assistant
Formatting now passes. This monorepo has no package-local
tsconfig, so that direct type-check route is unavailable; I’ll use the package build later. First I’ll run a comprehensive temporary contract test covering default clearing, preservation, override removal, function-valued configuration,can()no-op success, and explicitunsetMarkbehavior. - Assistant
All contract cases pass after the fix, including function-valued
clearableand explicitunsetMark. I’ll now run the full existing core test suite, then build@tiptap/corefrom its package directory to validate declaration generation and TypeScript types. - Assistant
The complete core suite passes (410/410). Declaration generation found one import error:
Storageis re-exported through the public index but is not declared intypes.ts. Rather than importing it at all, the command can safely index extension storage by the extension’s string name (the editor storage type supports that via a generic cast), or import the actual declaration source. I’ll locate the canonical type and apply the smallest type-correct fix, then rebuild. - Assistant
The canonical
Storageinterface lives incore/src/index.ts, andExtensionManageralready uses that public type for the identical indexing expression. I’ll mirror that established import pattern and rerun the core build. - Assistant
Python is unavailable in the environment, so that edit never occurred and the rebuild predictably repeated the same error. I’ll use the repository’s
replacecommand instead, verify the imports directly, and rebuild again. - Assistant
The core build now succeeds, including
.d.tsgeneration. I’ll perform final quality checks: inspectcallOrReturnfor undefined handling, run formatter/linter on changed files, confirm generated build artifacts are ignored/unmodified, and review the exact diff for unnecessary or risky changes.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.