Merge pull request #32628 from overleaf/em-bg-history-bug

Prevent incorrect merging of ops with different hpos offsets

GitOrigin-RevId: d171a93dcb29e952c7105afd81c3b29ca7e9788e
This commit is contained in:
Eric Mc Sween
2026-04-08 08:05:03 +00:00
committed by Copybot
parent 7e327ee548
commit 77952e5d21
2 changed files with 100 additions and 0 deletions
@@ -394,6 +394,16 @@ function _concatTwoUpdates(firstUpdate, secondUpdate) {
firstOp.p <= secondOp.p && secondOp.p <= firstOp.p + firstSize
const combinedLengthUnderLimit = firstSize + secondSize < MAX_UPDATE_SIZE
// When ops come from a multi-component update, the history position offset
// (hpos - p) may differ between ops because each component's hpos is computed
// against a different tracked-change state. Merging ops with different
// offsets would produce incorrect history positions, so we bail out.
const firstHposOffset = (firstOp.hpos ?? firstOp.p) - firstOp.p
const secondHposOffset = (secondOp.hpos ?? secondOp.p) - secondOp.p
if (firstHposOffset !== secondHposOffset) {
return [firstUpdate, secondUpdate]
}
// Two inserts
if (
firstOp.i != null &&