Skip to content

Commit 3ecb10f

Browse files
committed
fix(track-changes): merge textStyle attrs in format change snapshot
upsertMarkSnapshotByType replaced the entire mark snapshot when a second property of the same mark type changed (e.g. color then fontFamily on textStyle). This lost earlier tracked changes, so rejecting a multi-property format suggestion only reverted the last property instead of all of them. Merge attrs for marks of the same type instead of replacing the snapshot.
1 parent 33ea1e4 commit 3ecb10f

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

packages/super-editor/src/editors/v1/extensions/track-changes/trackChangesHelpers/markSnapshotHelpers.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,15 @@ export const hasMatchingMark = (marks, stepMark) => {
9292
};
9393

9494
export const upsertMarkSnapshotByType = (snapshots, incoming) => {
95-
const withoutSameType = snapshots.filter((mark) => mark.type !== incoming.type);
96-
return [...withoutSameType, incoming];
95+
const existing = snapshots.find((mark) => mark.type === incoming.type);
96+
if (existing) {
97+
const merged = {
98+
...existing,
99+
attrs: { ...existing.attrs, ...incoming.attrs },
100+
};
101+
return snapshots.map((mark) => (mark === existing ? merged : mark));
102+
}
103+
return [...snapshots, incoming];
97104
};
98105

99106
const markMatchesSnapshot = (mark, snapshot, exact = true) => {

0 commit comments

Comments
 (0)