Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/json-patch-ot/__tests__/scenarios.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -785,6 +785,14 @@ const groups: ScenarioGroup[] = [
user2: [{op: 'str_ins', path: '/a', pos: 2, str: '_bar_'}],
docEnd: {a: '12_foo__bar_345'},
},
{
// discard multiple same inserts (will typically happen in markdown task lists)
name: 'Inserts the same into same string at the same position.',
docStart: {a: '12345'},
user1: [{op: 'str_ins', path: '/a', pos: 2, str: '_foo_'}],
user2: [{op: 'str_ins', path: '/a', pos: 2, str: '_foo_'}],
docEnd: {a: '12_foo_345'},
},
],
},
{
Expand Down
1 change: 1 addition & 0 deletions src/json-patch-ot/transforms/xStrIns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {type Op, OpStrDel, OpStrIns} from '../../json-patch/op';
export const xStrIns = (ins: OpStrIns, op: Op): null | Op | Op[] => {
if (op instanceof OpStrIns) {
if (ins.pos > op.pos) return op;
if (ins.pos === op.pos && ins.str === op.str) return null; // discard equal inserts
return operationToOp({...op.toJson(), pos: op.pos + ins.str.length}, {});
} else if (op instanceof OpStrDel) {
const del = op;
Expand Down
Loading