mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-30 03:53:05 -05:00
21 lines
710 B
JavaScript
21 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
|
||
|
}
|