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.jseditor.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 inspect the core mark configuration, the current
unsetAllMarksimplementation, and nearby command tests/types to determine the smallest compatible change and how extension-comments declares its mark. - Assistant
The current command delegates to ProseMirror’s unfiltered
removeMark, so it necessarily removes semantic marks. I’ll now locate extension-field resolution patterns and comment mark declarations, then inspect test infrastructure for core commands. - Assistant
No comments package appears in this checkout’s shallow package search, so the core API must support downstream/pro comment marks generically. I’ll inspect
getExtensionField, command context, and existing command tests/package scripts before implementing field evaluation with the same inheritance/context semantics used elsewhere. - Assistant
A robust implementation should resolve
clearablefrom each registered mark extension (including inherited config), default missing values totrue, and remove each eligible ProseMirrorMarkTypeindividually. This preserves non-clearable marks without changing explicitunsetMark. I’ll verify helper binding details and transaction semantics, then edit only the two specified core files. - Assistant
I’ll add the optional
MarkConfig.clearablefield (documented defaulttrue) and changeunsetAllMarksto accept{ ignoreClearable?: boolean }. In normal mode it will resolve each mark’s configuration and remove only clearable mark types; override mode will retain the prior unfiltered behavior. The command will continue returningtruebefore dispatch, preservingcan()as a successful no-op. - Assistant
The edits completed, but the first validation invocation hit Corepack’s download confirmation and timed out. I’ll rerun non-interactively with Corepack’s prompt disabled and inspect the resulting type diagnostics; this should also confirm whether ProseMirror requires the resolved
MarkTyperather than a mark name. - Assistant
The timed-out tool call was rolled back entirely, so neither edit persisted. Also, core has no package-local tsconfig. I’ll reapply the source changes in a short command, using the resolved schema
MarkTypefor transaction removal, then identify the repository’s correct typecheck/build command. - Assistant
Python is unavailable in the environment (the earlier apparent execution never reached that step). I’ll use the repository editor commands instead: insert the config field after
addMarkView, then replace the command file wholesale. - Assistant
I’ll insert the documented field at the start of mark behavior options and write the command implementation with explicit eligibility resolution.
- Assistant
The source diff is syntactically clean. I’ll format both files and run the root build TypeScript configuration; if the monorepo build is too broad, I’ll additionally use the core package build, which generates and checks declarations for this public API.
- Assistant
The root typecheck is already broken by unrelated demo/module and duplicate dependency type errors; none shown involve these files. I’ll run the isolated
@tiptap/corepackage build next. Then I’ll create a temporary runtime script outside the repository tests to exercise default clearable marks,clearable: false, override mode, explicitunsetMark, andcan()behavior. - Assistant
The isolated declaration build found one relevant type issue: generic editor storage cannot be indexed by an arbitrary string. I’ll mirror
ExtensionManager’s establishedextension.name as keyof Storagepattern by importing theStoragetype, then rebuild. - Assistant
Storageis re-exported through the core index rather thantypes.ts; importing it from the command would introduce an undesirable self-index import. Since command logic only needs the extension’s own storage value, I’ll avoid the generic index entirely by usingextension.storage, which is the same instance assigned intoeditor.extensionStorageduring setup. Then I’ll rebuild. - Assistant
The core build and declaration generation now pass. I’ll run a temporary Node script against that built output using custom document, paragraph, clearable formatting, and non-clearable comment extensions. It will assert preservation, successful
can()no-op, explicit removal, and override removal without altering repository tests. - Assistant
Runtime verification was blocked because the built core package’s workspace dependency
@tiptap/pmhas not itself been built (its export points to a missingdistfile), not by the implementation. I’ll use the monorepo’s Vitest/Vite source-resolution setup instead, placing a temporary script at the repository root and removing it afterward. - Assistant
Vitest aliases all workspace packages to source and provides the DOM environment needed by
Editor. I’ll transiently create and execute a focused verification file, delete it in the same command, and retain only the source changes. - Assistant
The first transient test reached editor rendering but its minimal custom nodes lacked required
renderHTML; this is a test fixture issue, not command behavior. I’ll rerun with valid DOM serializers on paragraph and both marks so the behavior assertions execute. - Assistant
The focused runtime verification now passes all evaluation-contract cases. I’ll run the existing core
cantests plus the full core test directories to catch command regressions, then inspect the final diff/status for generated or accidental files. - Assistant
All 410 existing core tests pass. I’ll perform final lint/format/diff checks, ensure only the intended two source files are modified, and review the implementation one last time before submission.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.