mirror of
https://github.com/overleaf/overleaf.git
synced 2024-12-12 05:51:39 -05:00
ee85d948e2
GitOrigin-RevId: ef2ef77e26df59d1af3df6dc664e284d3c70102d
20 lines
710 B
JavaScript
20 lines
710 B
JavaScript
export function compressOperations(operations) {
|
|
if (!operations.length) return []
|
|
|
|
const newOperations = []
|
|
let currentOperation = operations[0]
|
|
for (let operationId = 1; operationId < operations.length; operationId++) {
|
|
const nextOperation = operations[operationId]
|
|
if (currentOperation.canBeComposedWith(nextOperation)) {
|
|
currentOperation = currentOperation.compose(nextOperation)
|
|
} else {
|
|
// currentOperation and nextOperation cannot be composed. Push the
|
|
// currentOperation and start over with nextOperation.
|
|
newOperations.push(currentOperation)
|
|
currentOperation = nextOperation
|
|
}
|
|
}
|
|
newOperations.push(currentOperation)
|
|
|
|
return newOperations
|
|
}
|