mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-06-10 22:50:46 +02:00
add test for non-overlapping insert-delete case
This commit is contained in:
@@ -133,6 +133,7 @@ module.exports = UpdateCompressor =
|
||||
else if firstOp.i? and secondOp.d? and firstOp.p <= secondOp.p <= (firstOp.p + firstOp.i.length)
|
||||
offset = secondOp.p - firstOp.p
|
||||
insertedText = firstOp.i.slice(offset, offset + secondOp.d.length)
|
||||
# Only trim the insert when the delete is fully contained within in it
|
||||
if insertedText == secondOp.d
|
||||
insert = strRemove(firstOp.i, offset, secondOp.d.length)
|
||||
return [
|
||||
@@ -146,7 +147,7 @@ module.exports = UpdateCompressor =
|
||||
v: secondUpdate.v
|
||||
]
|
||||
else
|
||||
# This shouldn't be possible!
|
||||
# This will only happen if the delete extends outside the insert
|
||||
return [firstUpdate, secondUpdate]
|
||||
|
||||
else
|
||||
|
||||
@@ -263,6 +263,26 @@ describe "UpdateCompressor", ->
|
||||
v: 43
|
||||
}]
|
||||
|
||||
it "should not combine updates with overlap beyond the end", ->
|
||||
expect(@UpdateCompressor.compressUpdates [{
|
||||
op: { p: 3, i: "foobar" }
|
||||
meta: ts: @ts1, user_id: @user_id
|
||||
v: 42
|
||||
}, {
|
||||
op: { p: 6, d: "bardle" }
|
||||
meta: ts: @ts2, user_id: @user_id
|
||||
v: 43
|
||||
}])
|
||||
.to.deep.equal [{
|
||||
op: { p: 3, i: "foobar" }
|
||||
meta: start_ts: @ts1, end_ts: @ts1, user_id: @user_id
|
||||
v: 42
|
||||
}, {
|
||||
op: { p: 6, d: "bardle" }
|
||||
meta: start_ts: @ts2, end_ts: @ts2, user_id: @user_id
|
||||
v: 43
|
||||
}]
|
||||
|
||||
describe "noop - insert", ->
|
||||
it "should leave them untouched", ->
|
||||
expect(@UpdateCompressor.compressUpdates [{
|
||||
|
||||
Reference in New Issue
Block a user