From 420039d3a7872e57b2937b1a3f1d38c2f9896e1b Mon Sep 17 00:00:00 2001 From: Lptenoss Date: Tue, 1 Dec 2026 15:15:27 +0700 Subject: [PATCH 1/5] fix(docx): a collaborator's change under my name is theirs: told by a mark of this editor, not by the file's w:id The editor told a change it had made from one made before by the w:id the file gives. A collaborator's change has none either, so under the same name (two people who never set one are both "Me"): - what I typed next to their insertion went on with it, under their date; - what I took out of it was gone for good, with nothing for a reviewer to see. The marks this editor makes now carry a symbol: copies keep it, the file and the collaboration (JSON) never get it. A change goes on with one carrying it only. Text taken out of an insertion under my name is gone for good when the insertion was made here or read from the file (as Word does); a collaborator's becomes a deletion that keeps it. Browser test: with the page's clock a second on at every reading, what is typed and struck out is one insertion and one deletion, so the mark is carried along by the editor. Co-Authored-By: Claude Opus 5.5 --- e2e/docx-track.spec.ts | 34 ++++++++++++++++++++++++++++++++++ src/react/docx/track.ts | 36 +++++++++++++++++++++++++----------- test/track.test.ts | 26 ++++++++++++++++++++++---- 3 files changed, 81 insertions(+), 15 deletions(-) diff --git a/e2e/docx-track.spec.ts b/e2e/docx-track.spec.ts index 27b3934..42ff6bd 100644 --- a/e2e/docx-track.spec.ts +++ b/e2e/docx-track.spec.ts @@ -76,4 +76,38 @@ describe('docx tracked changes', () => { expect(show(ps.find((p) => show(p).startsWith('Hire'))!)).toBe('Hire the platform team') expect(v.errors).toEqual([]) }) + + test('typed and struck out a second apart: one insertion and one deletion, as the editor carries its own marks along', async () => { + const v = await open('samples/sample.docx') + await v.btn('Track changes').click() + // the page's clock moves on a second at every reading: every key press is a second after the one before + const clock = (on: boolean) => + v.page.evaluate((on) => { + const w = window as unknown as { Date: DateConstructor; __Date?: DateConstructor } + w.__Date ??= w.Date + const D = w.__Date + if (!on) return void (w.Date = D) + let t = D.now() + w.Date = class extends D { + constructor(...a: unknown[]) { + if (a.length) super(...(a as [number])) + else super((t += 1000)) + } + static override now() { + return (t += 1000) + } + } as DateConstructor + }, on) + await v.selectText('Hire the platform team', 'end') + await clock(true) + await v.page.keyboard.type('xyz', { delay: 50 }) + await v.selectText('Hire the platform', 'end') + await v.page.keyboard.press('Backspace') + await v.page.keyboard.press('Backspace') + await v.page.waitForTimeout(250) + await clock(false) + const ps = await docxParas((await v.save()).bytes) + expect(show(ps.find((p) => show(p).startsWith('Hire'))!)).toBe('Hire the platfo[-rm] team[+xyz]') + expect(v.errors).toEqual([]) + }) }) diff --git a/src/react/docx/track.ts b/src/react/docx/track.ts index 87f78c4..fb12700 100644 --- a/src/react/docx/track.ts +++ b/src/react/docx/track.ts @@ -14,6 +14,17 @@ type Tok = { b: true } | { b?: false; ch: string; run: Inline; tc?: TrackMark; o const isText = (t: Tok): t is Extract => !t.b +/** + * On the marks this editor makes. A symbol is neither written to the file nor sent to collaborators (JSON leaves it + * out), so a change made here is told from one read from the file or made by a collaborator, even under the same name + * (two people who never set one are both "Me"; one person may be in a session twice). Copies of a mark keep it. + */ +const HERE = Symbol('made here') +type Here = TrackMark & { [HERE]?: true } +/** `m` as a mark made here */ +export const markHere = (m: TrackMark): TrackMark => ({ ...m, [HERE]: true }) as Here +export const madeHere = (m: TrackMark | undefined): boolean => !!m && !!(m as Here)[HERE] + function flatten(paras: Paragraph[]): Tok[] { const out: Tok[] = [] paras.forEach((p, i) => { @@ -96,13 +107,13 @@ export function trackEdit(before: Paragraph[], next: Paragraph[], pa0: string, s const inserted = N.slice(p, N.length - s) if (!removed.some(isText) && !inserted.some(isText)) return { next, sel } - // A change right next to one of the same kind by the same author, made since the document was opened, goes on with - // it, under its mark: letters typed one after another are one insertion of when it began, as in Word. (Every edit - // comes with a mark of its own time, and runs join only under the same mark: a word typed across the end of a second - // was two insertions.) A change read from the file has its w:id: it was made before, and what is typed now is a - // change of its own, of now, also when the author's name is the same (two people who never set one are both "Me"). + // A change right next to one of the same kind by the same author, made here, goes on with it, under its mark: + // letters typed one after another are one insertion of when it began, as in Word. (Every edit comes with a mark of + // its own time, and runs join only under the same mark: a word typed across the end of a second was two insertions.) + // A change read from the file, or a collaborator's, is not gone on with, even under the same name: what is typed now + // is a change of its own, of now. const own = (t: Tok | undefined, k: TrackMark['k']): TrackMark | undefined => { - if (!t || !isText(t) || t.obj || !t.tc || t.tc.k !== k || t.tc.author !== mark.author || t.tc.mv || t.tc.id !== undefined) return undefined + if (!t || !isText(t) || t.obj || !t.tc || t.tc.k !== k || t.tc.author !== mark.author || t.tc.mv || !madeHere(t.tc)) return undefined // (a deletion of text someone inserted carries that insertion: it belongs to that text, not to the change) const { ins: theirs, ...plain } = t.tc return theirs ? plain : t.tc @@ -110,9 +121,12 @@ export function trackEdit(before: Paragraph[], next: Paragraph[], pa0: string, s const left = p > 0 ? B[p - 1] : undefined const right = s > 0 ? B[B.length - s] : undefined - // what stays of the removed text: deleted marks. The author's own insertion taken out again is gone for good; - // someone else's becomes a deletion, so the reviewer still sees it. Objects go for real, unless already deleted. - const stays = removed.filter((t): t is Extract => isText(t) && (t.tc?.k === 'del' || (!t.obj && !(t.tc?.k === 'ins' && t.tc.author === mark.author)))) + // what stays of the removed text: deleted marks. The author's own insertion taken out again is gone for good, made + // here or read from the file under their name (as Word does); someone else's becomes a deletion, so the reviewer + // still sees it, and so does a collaborator's under the same name: it may be someone else's. Objects go for real, + // unless already deleted. + const mine = (tc: TrackMark | undefined) => tc?.k === 'ins' && tc.author === mark.author && (madeHere(tc) || tc.id !== undefined) + const stays = removed.filter((t): t is Extract => isText(t) && (t.tc?.k === 'del' || (!t.obj && !mine(t.tc)))) const struck = (t: Tok | undefined) => !!t && isText(t) && t.tc?.k !== 'del' const text = (t: Tok) => isText(t) && !t.obj // In the paragraph, the text before the edit is followed by what stays (deletions made before, and the text struck @@ -129,10 +143,10 @@ export function trackEdit(before: Paragraph[], next: Paragraph[], pa0: string, s const piece = first >= 0 && stays.slice(first, last + 1).every(struck) const del: TrackMark = (piece ? own(first > 0 ? stays[first - 1] : left, 'del') ?? own(last < stays.length - 1 ? stays[last + 1] : inserted.length ? undefined : right, 'del') : undefined) ?? - { ...mark, k: 'del' } + markHere({ ...mark, k: 'del' }) const kept = stays.map((t) => (struck(t) ? { ...t, tc: t.tc?.k === 'ins' ? { ...del, ins: t.tc } : del } : t)) const ins: TrackMark = - (inserted.length && inserted.every(text) ? own(stays.length ? stays[stays.length - 1] : left, 'ins') ?? own(right, 'ins') : undefined) ?? { ...mark, k: 'ins' } + (inserted.length && inserted.every(text) ? own(stays.length ? stays[stays.length - 1] : left, 'ins') ?? own(right, 'ins') : undefined) ?? markHere({ ...mark, k: 'ins' }) // the paragraphs of `next`, the kept text put back where the removal was, the new text marked const paras: Extract[][] = [[]] diff --git a/test/track.test.ts b/test/track.test.ts index b37cb0b..5553c64 100644 --- a/test/track.test.ts +++ b/test/track.test.ts @@ -1,7 +1,7 @@ import { describe, expect, test } from 'bun:test' import type { Inline, Paragraph, TrackMark } from '../src/core/docx/types' import { deleteRange, insertText, type RRun } from '../src/react/edit/rich' -import { changeSpans, resolveRuns, trackEdit } from '../src/react/docx/track' +import { changeSpans, madeHere, markHere, resolveRuns, trackEdit } from '../src/react/docx/track' const ME: TrackMark = { k: 'ins', author: 'Vy', date: '2026-11-08T10:00:00Z' } const para = (runs: Inline[], pid = 1): Paragraph => ({ t: 'p', ps: {}, runs, pid }) @@ -17,7 +17,8 @@ describe('tracking an edit', () => { const r = trackEdit([b], [n], '0', caret(9), caret(5), ME) expect(show(r.next[0])).toBe('Hello[+ big] world') const ins = r.next[0].runs[1] as Inline & { t: 'text' } - expect(ins.tc).toEqual({ k: 'ins', author: 'Vy', date: '2026-11-08T10:00:00Z' }) + expect(ins.tc).toEqual(markHere({ k: 'ins', author: 'Vy', date: '2026-11-08T10:00:00Z' })) + expect(madeHere(ins.tc)).toBe(true) expect(r.sel).toEqual(caret(9)) }) @@ -50,7 +51,7 @@ describe('tracking an edit', () => { }) test('removing text I inserted removes it for real; others’ deletions stay', () => { - const b = para([t('ab'), { ...t('XY'), tc: { k: 'ins', author: 'Vy' } } as Inline, t('cd', 'del'), t('e')]) + const b = para([t('ab'), { ...t('XY'), tc: markHere({ k: 'ins', author: 'Vy' }) } as Inline, t('cd', 'del'), t('e')]) const n = para(deleteRange(b.runs as RRun[], 1, 6) as Inline[]) const r = trackEdit([b], [n], '0', caret(1), { a: { pa: '0', o: 1 }, f: { pa: '0', o: 6 } }, ME) // "XY" (mine) is gone; "b" is deleted by me, "cd" stays deleted by Lan @@ -119,7 +120,7 @@ describe('tracking an edit', () => { }) test('a change goes on with one of mine only where they touch', () => { - const mine = (text: string, k: TrackMark['k'], s: number) => ({ ...t(text), tc: { ...at(s), k } }) as Inline + const mine = (text: string, k: TrackMark['k'], s: number) => ({ ...t(text), tc: markHere({ ...at(s), k }) }) as Inline const range = (a: number, f: number) => ({ a: { pa: '0', o: a }, f: { pa: '0', o: f } }) const b = para([t('ab'), mine('X', 'del', 0), t('e')]) @@ -163,6 +164,23 @@ describe('tracking an edit', () => { const gone = para([t('Hell'), { ...t('o'), tc: { ...old, k: 'del' } } as Inline]) const struck = trackEdit([gone], [para(deleteRange(gone.runs as RRun[], 3, 4) as Inline[])], '0', caret(3), caret(4), at(0)).next[0] expect([show(struck), dates(struck)]).toEqual(['Hel[-l][-o]', [at(0).date, old.date]]) + + // my insertion read from the file, taken out: gone for good, as in Word + const out = trackEdit([file], [para([t('tea')])], '0', caret(3), caret(4), at(0)).next[0] + expect(show(out)).toBe('tea') + }) + + test('a collaborator’s change under my name (no w:id, not made here) is theirs: not gone on with, not taken out for good', () => { + // (what a collaborator types comes as JSON: no id yet, and no mark of this editor) + const theirs: TrackMark = JSON.parse(JSON.stringify(markHere({ k: 'ins', author: 'Vy', date: '2026-11-08T09:00:00Z' }))) + expect(madeHere(theirs)).toBe(false) + const shared = para([t('tea'), { ...t('m'), tc: theirs } as Inline]) + const typed = trackEdit([shared], [para(insertText(shared.runs as RRun[], 4, 's') as Inline[])], '0', caret(5), caret(4), at(0)).next[0] + expect([show(typed), dates(typed)]).toEqual(['tea[+m][+s]', [theirs.date, at(0).date]]) + + const out = trackEdit([shared], [para([t('tea')])], '0', caret(3), caret(4), at(0)).next[0] + expect(show(out)).toBe('tea[-m]') + expect((out.runs[1] as { tc: TrackMark }).tc.ins).toEqual(theirs) }) }) From ac3812b9430690a32afb2a8eee73f0f0098c703a Mon Sep 17 00:00:00 2001 From: Lptenoss Date: Tue, 1 Dec 2026 15:15:27 +0700 Subject: [PATCH 2/5] fix(docx): text decoration in longhands, so React does not warn when a run's style changes A tracked run had `textDecoration` and `textDecorationColor`, a formatted one `textDecoration` and `textDecorationStyle`: React warns ("Updating a style property during rerender ... when a conflicting property is set") when such a span's style changes, as when text next to it is struck out. `textDecorationLine` draws the same. Co-Authored-By: Claude Opus 5.5 --- src/react/docx/render.tsx | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/react/docx/render.tsx b/src/react/docx/render.tsx index 1b9fd2b..9e28399 100644 --- a/src/react/docx/render.tsx +++ b/src/react/docx/render.tsx @@ -51,12 +51,15 @@ export function authorColor(author: string | undefined): string { return TRACK_COLORS[i % TRACK_COLORS.length] } -/** inserted text underlined, deleted text struck through, in the author's colour */ +/** + * inserted text underlined, deleted text struck through, in the author's colour. (Longhands only, here and in `runCss`: + * React warns when a run's style changes and has both a shorthand and one of its longhands.) + */ function trackCss(tc: TrackMark): CSSProperties { const color = authorColor(tc.author) return tc.k === 'ins' - ? { color, textDecoration: 'underline', textDecorationColor: color } - : { color, textDecoration: 'line-through', textDecorationColor: color } + ? { color, textDecorationLine: 'underline', textDecorationColor: color } + : { color, textDecorationLine: 'line-through', textDecorationColor: color } } export function runCss(s: RunStyle | undefined): CSSProperties { @@ -68,8 +71,8 @@ export function runCss(s: RunStyle | undefined): CSSProperties { else if (s.i === false) css.fontStyle = 'normal' const u = s.u && s.u !== 'none' const deco = [u ? 'underline' : '', s.strike || s.dstrike ? 'line-through' : ''].filter(Boolean).join(' ') - if (deco) css.textDecoration = deco - else if (s.u === 'none' || s.strike === false) css.textDecoration = 'none' + if (deco) css.textDecorationLine = deco + else if (s.u === 'none' || s.strike === false) css.textDecorationLine = 'none' if (u && UNDERLINE_STYLE[s.u!]) css.textDecorationStyle = UNDERLINE_STYLE[s.u!] if (s.dstrike) css.textDecorationStyle = 'double' // colors of the model come from the file, a peer or the clipboard: `background` would load a url() in one From 8f01bbd154d07d4cc585a3be1e3d8634cd107481 Mon Sep 17 00:00:00 2001 From: Lptenoss Date: Tue, 1 Dec 2026 16:02:55 +0700 Subject: [PATCH 3/5] revert(docx): changes made here are told again by the file's w:id, not by a mark of this editor Review: a collaborator's change rewrites a whole paragraph with copies that come as JSON, so the symbol on my own marks was lost. My own insertion was then taken for someone else's: Backspace struck it through instead of removing it, and typing next to it began a new change, in any shared session, also with different names. That is worse than the case it was for (two collaborators under the same name), which no mark kept by this editor can tell apart: the collaboration has no stable user id to go by (`UserInfo.id` is optional, a peer's `site` changes with the connection). Back to the rules on main. Co-Authored-By: Claude Opus 5.5 --- src/react/docx/track.ts | 36 +++++++++++------------------------- test/track.test.ts | 26 ++++---------------------- 2 files changed, 15 insertions(+), 47 deletions(-) diff --git a/src/react/docx/track.ts b/src/react/docx/track.ts index fb12700..87f78c4 100644 --- a/src/react/docx/track.ts +++ b/src/react/docx/track.ts @@ -14,17 +14,6 @@ type Tok = { b: true } | { b?: false; ch: string; run: Inline; tc?: TrackMark; o const isText = (t: Tok): t is Extract => !t.b -/** - * On the marks this editor makes. A symbol is neither written to the file nor sent to collaborators (JSON leaves it - * out), so a change made here is told from one read from the file or made by a collaborator, even under the same name - * (two people who never set one are both "Me"; one person may be in a session twice). Copies of a mark keep it. - */ -const HERE = Symbol('made here') -type Here = TrackMark & { [HERE]?: true } -/** `m` as a mark made here */ -export const markHere = (m: TrackMark): TrackMark => ({ ...m, [HERE]: true }) as Here -export const madeHere = (m: TrackMark | undefined): boolean => !!m && !!(m as Here)[HERE] - function flatten(paras: Paragraph[]): Tok[] { const out: Tok[] = [] paras.forEach((p, i) => { @@ -107,13 +96,13 @@ export function trackEdit(before: Paragraph[], next: Paragraph[], pa0: string, s const inserted = N.slice(p, N.length - s) if (!removed.some(isText) && !inserted.some(isText)) return { next, sel } - // A change right next to one of the same kind by the same author, made here, goes on with it, under its mark: - // letters typed one after another are one insertion of when it began, as in Word. (Every edit comes with a mark of - // its own time, and runs join only under the same mark: a word typed across the end of a second was two insertions.) - // A change read from the file, or a collaborator's, is not gone on with, even under the same name: what is typed now - // is a change of its own, of now. + // A change right next to one of the same kind by the same author, made since the document was opened, goes on with + // it, under its mark: letters typed one after another are one insertion of when it began, as in Word. (Every edit + // comes with a mark of its own time, and runs join only under the same mark: a word typed across the end of a second + // was two insertions.) A change read from the file has its w:id: it was made before, and what is typed now is a + // change of its own, of now, also when the author's name is the same (two people who never set one are both "Me"). const own = (t: Tok | undefined, k: TrackMark['k']): TrackMark | undefined => { - if (!t || !isText(t) || t.obj || !t.tc || t.tc.k !== k || t.tc.author !== mark.author || t.tc.mv || !madeHere(t.tc)) return undefined + if (!t || !isText(t) || t.obj || !t.tc || t.tc.k !== k || t.tc.author !== mark.author || t.tc.mv || t.tc.id !== undefined) return undefined // (a deletion of text someone inserted carries that insertion: it belongs to that text, not to the change) const { ins: theirs, ...plain } = t.tc return theirs ? plain : t.tc @@ -121,12 +110,9 @@ export function trackEdit(before: Paragraph[], next: Paragraph[], pa0: string, s const left = p > 0 ? B[p - 1] : undefined const right = s > 0 ? B[B.length - s] : undefined - // what stays of the removed text: deleted marks. The author's own insertion taken out again is gone for good, made - // here or read from the file under their name (as Word does); someone else's becomes a deletion, so the reviewer - // still sees it, and so does a collaborator's under the same name: it may be someone else's. Objects go for real, - // unless already deleted. - const mine = (tc: TrackMark | undefined) => tc?.k === 'ins' && tc.author === mark.author && (madeHere(tc) || tc.id !== undefined) - const stays = removed.filter((t): t is Extract => isText(t) && (t.tc?.k === 'del' || (!t.obj && !mine(t.tc)))) + // what stays of the removed text: deleted marks. The author's own insertion taken out again is gone for good; + // someone else's becomes a deletion, so the reviewer still sees it. Objects go for real, unless already deleted. + const stays = removed.filter((t): t is Extract => isText(t) && (t.tc?.k === 'del' || (!t.obj && !(t.tc?.k === 'ins' && t.tc.author === mark.author)))) const struck = (t: Tok | undefined) => !!t && isText(t) && t.tc?.k !== 'del' const text = (t: Tok) => isText(t) && !t.obj // In the paragraph, the text before the edit is followed by what stays (deletions made before, and the text struck @@ -143,10 +129,10 @@ export function trackEdit(before: Paragraph[], next: Paragraph[], pa0: string, s const piece = first >= 0 && stays.slice(first, last + 1).every(struck) const del: TrackMark = (piece ? own(first > 0 ? stays[first - 1] : left, 'del') ?? own(last < stays.length - 1 ? stays[last + 1] : inserted.length ? undefined : right, 'del') : undefined) ?? - markHere({ ...mark, k: 'del' }) + { ...mark, k: 'del' } const kept = stays.map((t) => (struck(t) ? { ...t, tc: t.tc?.k === 'ins' ? { ...del, ins: t.tc } : del } : t)) const ins: TrackMark = - (inserted.length && inserted.every(text) ? own(stays.length ? stays[stays.length - 1] : left, 'ins') ?? own(right, 'ins') : undefined) ?? markHere({ ...mark, k: 'ins' }) + (inserted.length && inserted.every(text) ? own(stays.length ? stays[stays.length - 1] : left, 'ins') ?? own(right, 'ins') : undefined) ?? { ...mark, k: 'ins' } // the paragraphs of `next`, the kept text put back where the removal was, the new text marked const paras: Extract[][] = [[]] diff --git a/test/track.test.ts b/test/track.test.ts index 5553c64..b37cb0b 100644 --- a/test/track.test.ts +++ b/test/track.test.ts @@ -1,7 +1,7 @@ import { describe, expect, test } from 'bun:test' import type { Inline, Paragraph, TrackMark } from '../src/core/docx/types' import { deleteRange, insertText, type RRun } from '../src/react/edit/rich' -import { changeSpans, madeHere, markHere, resolveRuns, trackEdit } from '../src/react/docx/track' +import { changeSpans, resolveRuns, trackEdit } from '../src/react/docx/track' const ME: TrackMark = { k: 'ins', author: 'Vy', date: '2026-11-08T10:00:00Z' } const para = (runs: Inline[], pid = 1): Paragraph => ({ t: 'p', ps: {}, runs, pid }) @@ -17,8 +17,7 @@ describe('tracking an edit', () => { const r = trackEdit([b], [n], '0', caret(9), caret(5), ME) expect(show(r.next[0])).toBe('Hello[+ big] world') const ins = r.next[0].runs[1] as Inline & { t: 'text' } - expect(ins.tc).toEqual(markHere({ k: 'ins', author: 'Vy', date: '2026-11-08T10:00:00Z' })) - expect(madeHere(ins.tc)).toBe(true) + expect(ins.tc).toEqual({ k: 'ins', author: 'Vy', date: '2026-11-08T10:00:00Z' }) expect(r.sel).toEqual(caret(9)) }) @@ -51,7 +50,7 @@ describe('tracking an edit', () => { }) test('removing text I inserted removes it for real; others’ deletions stay', () => { - const b = para([t('ab'), { ...t('XY'), tc: markHere({ k: 'ins', author: 'Vy' }) } as Inline, t('cd', 'del'), t('e')]) + const b = para([t('ab'), { ...t('XY'), tc: { k: 'ins', author: 'Vy' } } as Inline, t('cd', 'del'), t('e')]) const n = para(deleteRange(b.runs as RRun[], 1, 6) as Inline[]) const r = trackEdit([b], [n], '0', caret(1), { a: { pa: '0', o: 1 }, f: { pa: '0', o: 6 } }, ME) // "XY" (mine) is gone; "b" is deleted by me, "cd" stays deleted by Lan @@ -120,7 +119,7 @@ describe('tracking an edit', () => { }) test('a change goes on with one of mine only where they touch', () => { - const mine = (text: string, k: TrackMark['k'], s: number) => ({ ...t(text), tc: markHere({ ...at(s), k }) }) as Inline + const mine = (text: string, k: TrackMark['k'], s: number) => ({ ...t(text), tc: { ...at(s), k } }) as Inline const range = (a: number, f: number) => ({ a: { pa: '0', o: a }, f: { pa: '0', o: f } }) const b = para([t('ab'), mine('X', 'del', 0), t('e')]) @@ -164,23 +163,6 @@ describe('tracking an edit', () => { const gone = para([t('Hell'), { ...t('o'), tc: { ...old, k: 'del' } } as Inline]) const struck = trackEdit([gone], [para(deleteRange(gone.runs as RRun[], 3, 4) as Inline[])], '0', caret(3), caret(4), at(0)).next[0] expect([show(struck), dates(struck)]).toEqual(['Hel[-l][-o]', [at(0).date, old.date]]) - - // my insertion read from the file, taken out: gone for good, as in Word - const out = trackEdit([file], [para([t('tea')])], '0', caret(3), caret(4), at(0)).next[0] - expect(show(out)).toBe('tea') - }) - - test('a collaborator’s change under my name (no w:id, not made here) is theirs: not gone on with, not taken out for good', () => { - // (what a collaborator types comes as JSON: no id yet, and no mark of this editor) - const theirs: TrackMark = JSON.parse(JSON.stringify(markHere({ k: 'ins', author: 'Vy', date: '2026-11-08T09:00:00Z' }))) - expect(madeHere(theirs)).toBe(false) - const shared = para([t('tea'), { ...t('m'), tc: theirs } as Inline]) - const typed = trackEdit([shared], [para(insertText(shared.runs as RRun[], 4, 's') as Inline[])], '0', caret(5), caret(4), at(0)).next[0] - expect([show(typed), dates(typed)]).toEqual(['tea[+m][+s]', [theirs.date, at(0).date]]) - - const out = trackEdit([shared], [para([t('tea')])], '0', caret(3), caret(4), at(0)).next[0] - expect(show(out)).toBe('tea[-m]') - expect((out.runs[1] as { tc: TrackMark }).tc.ins).toEqual(theirs) }) }) From 5f543abd71f088562a908a1c96d9e9fe66d3f5f4 Mon Sep 17 00:00:00 2001 From: Lptenoss Date: Tue, 1 Dec 2026 16:02:55 +0700 Subject: [PATCH 4/5] fix(docx): tracked text keeps its own lines under the change's Struck-through text inserted with Track changes on showed only the change's underline (and underlined text deleted only the strike line): the change's line replaced the text's. The change's line is now added to the text's own, in one solid style. Co-Authored-By: Claude Opus 5.5 --- src/react/docx/render.tsx | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/react/docx/render.tsx b/src/react/docx/render.tsx index 9e28399..296e007 100644 --- a/src/react/docx/render.tsx +++ b/src/react/docx/render.tsx @@ -52,14 +52,16 @@ export function authorColor(author: string | undefined): string { } /** - * inserted text underlined, deleted text struck through, in the author's colour. (Longhands only, here and in `runCss`: - * React warns when a run's style changes and has both a shorthand and one of its longhands.) + * `run`'s style as a tracked change: inserted text underlined, deleted text struck through, in the author's colour, + * with the lines the text has of its own (struck-through text inserted is still struck through). One style for all + * the lines: solid, as the change's. (Longhands only, here and in `runCss`: React warns when a run's style changes + * and has both a shorthand and one of its longhands.) */ -function trackCss(tc: TrackMark): CSSProperties { +function trackCss(tc: TrackMark, run: CSSProperties): CSSProperties { const color = authorColor(tc.author) - return tc.k === 'ins' - ? { color, textDecorationLine: 'underline', textDecorationColor: color } - : { color, textDecorationLine: 'line-through', textDecorationColor: color } + const own = String(run.textDecorationLine ?? '').split(' ').filter((x) => x && x !== 'none') + const line = tc.k === 'ins' ? 'underline' : 'line-through' + return { ...run, color, textDecorationLine: [...new Set([...own, line])].join(' '), textDecorationColor: color, textDecorationStyle: 'solid' } } export function runCss(s: RunStyle | undefined): CSSProperties { @@ -247,7 +249,7 @@ function InlineView({ x, ctx, o, pieces, tabs }: { x: Inline; ctx: RenderCtx; o: const span = ( Date: Tue, 1 Dec 2026 16:02:55 +0700 Subject: [PATCH 5/5] test(e2e): the clock test goes by main's rules, and struck-through text inserted shows both lines Co-Authored-By: Claude Opus 5.5 --- e2e/docx-track.spec.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/e2e/docx-track.spec.ts b/e2e/docx-track.spec.ts index 42ff6bd..7d3788b 100644 --- a/e2e/docx-track.spec.ts +++ b/e2e/docx-track.spec.ts @@ -77,7 +77,7 @@ describe('docx tracked changes', () => { expect(v.errors).toEqual([]) }) - test('typed and struck out a second apart: one insertion and one deletion, as the editor carries its own marks along', async () => { + test('typed and struck out a second apart: one insertion and one deletion; struck-through text inserted keeps its line', async () => { const v = await open('samples/sample.docx') await v.btn('Track changes').click() // the page's clock moves on a second at every reading: every key press is a second after the one before @@ -108,6 +108,13 @@ describe('docx tracked changes', () => { await clock(false) const ps = await docxParas((await v.save()).bytes) expect(show(ps.find((p) => show(p).startsWith('Hire'))!)).toBe('Hire the platfo[-rm] team[+xyz]') + + // the inserted text struck through (formatting is not tracked): both lines show, the change's and the text's own + await v.selectText('xyz') + await v.btn('Strikethrough').click() + const xyz = v.page.locator('.de-pages [data-tc="ins"]', { hasText: 'xyz' }) + await v.page.waitForFunction(() => [...document.querySelectorAll('.de-pages [data-tc="ins"]')].some((el) => el.textContent === 'xyz' && getComputedStyle(el).textDecorationLine.includes('line-through'))) + expect(await xyz.evaluate((el) => getComputedStyle(el).textDecorationLine)).toContain('underline') expect(v.errors).toEqual([]) }) })