Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1144,7 +1144,10 @@ const createOrUpdateTrackedChangeComment = ({
trackedChangeType: isDeletionInsertion ? 'both' : trackedChangeType,
trackedChangeText,
trackedChangeDisplayType,
deletedText: marks.deletionMark ? deletionText : null,
// Replacement updates can arrive with insert-only transaction meta while the
// document still contains both insert+delete marks for the same change id.
// In that case isDeletionInsertion is true and we must keep deleted text.
deletedText: isDeletionInsertion || marks.deletionMark ? deletionText : null,
author,
authorEmail,
...(authorImage && { authorImage }),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1124,6 +1124,47 @@ describe('internal helper functions', () => {
expect(payload?.deletedText).toBe('original');
});

it('preserves deletedText on replacement update when transaction meta only carries insertion mark', () => {
const schema = createCommentSchema();
const insertMark = schema.marks[TrackInsertMarkName].create({
id: 'replace-update-1',
author: 'Author',
authorEmail: 'author@example.com',
date: 'today',
});
const deleteMark = schema.marks[TrackDeleteMarkName].create({
id: 'replace-update-1',
author: 'Author',
authorEmail: 'author@example.com',
date: 'today',
});

const docInsertNode = schema.text('replacement', [insertMark]);
const docDeleteNode = schema.text('original', [deleteMark]);
const doc = schema.node('doc', null, [schema.node('paragraph', null, [docInsertNode, docDeleteNode])]);
const state = EditorState.create({ schema, doc });

// Simulate an update transaction where meta has only insertedMark, but the
// document still has both insert+delete marks under the same tracked-change id.
const payload = createOrUpdateTrackedChangeComment({
event: 'update',
marks: { insertedMark: insertMark, deletionMark: null, formatMark: null },
deletionNodes: [],
nodes: [schema.text('replacement', [insertMark])],
newEditorState: state,
documentId: 'doc-1',
trackedChangesForId: [
{ mark: insertMark, from: 1, to: doc.content.size },
{ mark: deleteMark, from: 1, to: doc.content.size },
],
});

expect(payload?.event).toBe(comments_module_events.UPDATE);
expect(payload?.trackedChangeType).toBe('both');
expect(payload?.trackedChangeText).toBe('replacement');
expect(payload?.deletedText).toBe('original');
});

it('createOrUpdateTrackedChangeComment builds add and update payloads', () => {
const schema = createCommentSchema();
const insertMark = schema.marks[TrackInsertMarkName].create({
Expand Down
Loading