Skip to content

Commit 28ce971

Browse files
artem-harbourArtem Nistuley
authored andcommitted
fix: replacement text in bubble
1 parent 4ba8992 commit 28ce971

2 files changed

Lines changed: 45 additions & 1 deletion

File tree

packages/super-editor/src/editors/v1/extensions/comment/comments-plugin.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1144,7 +1144,10 @@ const createOrUpdateTrackedChangeComment = ({
11441144
trackedChangeType: isDeletionInsertion ? 'both' : trackedChangeType,
11451145
trackedChangeText,
11461146
trackedChangeDisplayType,
1147-
deletedText: marks.deletionMark ? deletionText : null,
1147+
// Replacement updates can arrive with insert-only transaction meta while the
1148+
// document still contains both insert+delete marks for the same change id.
1149+
// In that case isDeletionInsertion is true and we must keep deleted text.
1150+
deletedText: isDeletionInsertion || marks.deletionMark ? deletionText : null,
11481151
author,
11491152
authorEmail,
11501153
...(authorImage && { authorImage }),

packages/super-editor/src/editors/v1/extensions/comment/comments-plugin.test.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1124,6 +1124,47 @@ describe('internal helper functions', () => {
11241124
expect(payload?.deletedText).toBe('original');
11251125
});
11261126

1127+
it('preserves deletedText on replacement update when transaction meta only carries insertion mark', () => {
1128+
const schema = createCommentSchema();
1129+
const insertMark = schema.marks[TrackInsertMarkName].create({
1130+
id: 'replace-update-1',
1131+
author: 'Author',
1132+
authorEmail: 'author@example.com',
1133+
date: 'today',
1134+
});
1135+
const deleteMark = schema.marks[TrackDeleteMarkName].create({
1136+
id: 'replace-update-1',
1137+
author: 'Author',
1138+
authorEmail: 'author@example.com',
1139+
date: 'today',
1140+
});
1141+
1142+
const docInsertNode = schema.text('replacement', [insertMark]);
1143+
const docDeleteNode = schema.text('original', [deleteMark]);
1144+
const doc = schema.node('doc', null, [schema.node('paragraph', null, [docInsertNode, docDeleteNode])]);
1145+
const state = EditorState.create({ schema, doc });
1146+
1147+
// Simulate an update transaction where meta has only insertedMark, but the
1148+
// document still has both insert+delete marks under the same tracked-change id.
1149+
const payload = createOrUpdateTrackedChangeComment({
1150+
event: 'update',
1151+
marks: { insertedMark: insertMark, deletionMark: null, formatMark: null },
1152+
deletionNodes: [],
1153+
nodes: [schema.text('replacement', [insertMark])],
1154+
newEditorState: state,
1155+
documentId: 'doc-1',
1156+
trackedChangesForId: [
1157+
{ mark: insertMark, from: 1, to: doc.content.size },
1158+
{ mark: deleteMark, from: 1, to: doc.content.size },
1159+
],
1160+
});
1161+
1162+
expect(payload?.event).toBe(comments_module_events.UPDATE);
1163+
expect(payload?.trackedChangeType).toBe('both');
1164+
expect(payload?.trackedChangeText).toBe('replacement');
1165+
expect(payload?.deletedText).toBe('original');
1166+
});
1167+
11271168
it('createOrUpdateTrackedChangeComment builds add and update payloads', () => {
11281169
const schema = createCommentSchema();
11291170
const insertMark = schema.marks[TrackInsertMarkName].create({

0 commit comments

Comments
 (0)