Skip to content

Commit c4af982

Browse files
committed
fix(json-patch-ot): merge equal str_ins operations at same position
1 parent ed523e1 commit c4af982

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

packages/json-joy/src/json-patch-ot/__tests__/scenarios.spec.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -785,6 +785,14 @@ const groups: ScenarioGroup[] = [
785785
user2: [{op: 'str_ins', path: '/a', pos: 2, str: '_bar_'}],
786786
docEnd: {a: '12_foo__bar_345'},
787787
},
788+
{
789+
// changed: discard multiple same inserts (will typically happen in markdown task lists)
790+
name: 'Merge equal inserts at same position.',
791+
docStart: {a: '12345'},
792+
user1: [{op: 'str_ins', path: '/a', pos: 2, str: '_foo_'}],
793+
user2: [{op: 'str_ins', path: '/a', pos: 2, str: '_foo_'}],
794+
docEnd: {a: '12_foo_345'},
795+
},
788796
],
789797
},
790798
{

packages/json-joy/src/json-patch-ot/transforms/xStrIns.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export const xStrIns = (ins: OpStrIns, op: Op): null | Op | Op[] => {
66
if (op instanceof OpStrIns) {
77
if (!isPathEqual(ins.path, op.path)) return op;
88
if (ins.pos > op.pos) return op;
9+
if (ins.pos === op.pos && ins.str === op.str) return null;
910
return operationToOp({...op.toJson(), pos: op.pos + ins.str.length}, {});
1011
} else if (op instanceof OpStrDel) {
1112
if (!isPathEqual(ins.path, op.path)) return op;

0 commit comments

Comments
 (0)