Skip to content

Commit 27c76c6

Browse files
authored
fix(converter): preserve CommentReference rStyle on comment anchor runs (SD-2910) (#3252)
The exporter synthesizes a fresh <w:r> to carry the inline <w:commentReference/> marker after each commentRangeEnd, but emitted no run properties. Word marks these anchor runs with <w:rPr><w:rStyle w:val="CommentReference"/></w:rPr>, so round-tripping a commented DOCX dropped the rStyle reference (11 -> 0 on the reported fixture). The importer cannot carry the source w:rPr through (the commentReference element is consumed by comments-list import), so emit the canonical rStyle when synthesizing the anchor run. Updates the two existing assertions that pinned the old shape (plain and trackDelete-marked variants) to match the corrected output.
1 parent de7dcbc commit 27c76c6

2 files changed

Lines changed: 22 additions & 9 deletions

File tree

packages/super-editor/src/editors/v1/core/super-converter/v3/handlers/w/commentRange/comment-range-translator.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,16 @@ const decode = (params) => {
5151
let commentSchema = getCommentSchema(type, commentIndex);
5252

5353
if (type === 'commentRangeEnd') {
54+
// SD-2910: Word marks comment-anchor runs with w:rStyle="CommentReference" so the
55+
// marker renders with the expected appearance. The importer drops the source w:rPr
56+
// (commentReference is consumed by the comments-list import), so we synthesize the
57+
// canonical rStyle here on every round-trip.
5458
const commentReference = {
5559
name: 'w:r',
56-
elements: [{ name: 'w:commentReference', attributes: { 'w:id': String(commentIndex) } }],
60+
elements: [
61+
{ name: 'w:rPr', elements: [{ name: 'w:rStyle', attributes: { 'w:val': 'CommentReference' } }] },
62+
{ name: 'w:commentReference', attributes: { 'w:id': String(commentIndex) } },
63+
],
5764
};
5865
commentSchema = [commentSchema, commentReference];
5966
}

packages/super-editor/src/editors/v1/core/super-converter/v3/handlers/w/commentRange/comment-range-translator.test.js

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ describe('w:commentRangeStart and w:commentRangeEnd', () => {
100100
});
101101

102102
describe('decode:commentRangeEndTranslator', () => {
103-
test('returns comment schema', () => {
103+
test('returns comment schema with CommentReference rStyle on the synthesized anchor run (SD-2910)', () => {
104104
expect(
105105
commentRangeEndTranslator.decode({
106106
node: { type: 'commentRangeEnd', attrs: { 'w:id': 'id1' } },
@@ -111,15 +111,14 @@ describe('w:commentRangeStart and w:commentRangeEnd', () => {
111111
).toStrictEqual([
112112
{ attributes: { 'w:id': '0' }, name: 'w:commentRangeEnd' },
113113
{
114+
name: 'w:r',
114115
elements: [
115116
{
116-
attributes: {
117-
'w:id': '0',
118-
},
119-
name: 'w:commentReference',
117+
name: 'w:rPr',
118+
elements: [{ name: 'w:rStyle', attributes: { 'w:val': 'CommentReference' } }],
120119
},
120+
{ name: 'w:commentReference', attributes: { 'w:id': '0' } },
121121
],
122-
name: 'w:r',
123122
},
124123
]);
125124
});
@@ -180,12 +179,19 @@ describe('w:commentRangeStart and w:commentRangeEnd', () => {
180179
commentsExportType: 'external',
181180
});
182181

183-
// Should return bare comment markers, not wrapped in w:del
182+
// Should return bare comment markers, not wrapped in w:del.
183+
// The synthesized anchor run must carry the CommentReference rStyle (SD-2910).
184184
expect(result).toStrictEqual([
185185
{ name: 'w:commentRangeEnd', attributes: { 'w:id': '0' } },
186186
{
187187
name: 'w:r',
188-
elements: [{ name: 'w:commentReference', attributes: { 'w:id': '0' } }],
188+
elements: [
189+
{
190+
name: 'w:rPr',
191+
elements: [{ name: 'w:rStyle', attributes: { 'w:val': 'CommentReference' } }],
192+
},
193+
{ name: 'w:commentReference', attributes: { 'w:id': '0' } },
194+
],
189195
},
190196
]);
191197
});

0 commit comments

Comments
 (0)