in backend/new.js [728:763]
function appendEdit(existingEdits, nextEdit) {
if (existingEdits.length === 0) {
existingEdits.push(nextEdit)
return
}
let lastEdit = existingEdits[existingEdits.length - 1]
if (lastEdit.action === 'insert' && nextEdit.action === 'insert' &&
lastEdit.index === nextEdit.index - 1 &&
lastEdit.value.type === 'value' && nextEdit.value.type === 'value' &&
lastEdit.elemId === lastEdit.opId && nextEdit.elemId === nextEdit.opId &&
opIdDelta(lastEdit.elemId, nextEdit.elemId, 1) &&
lastEdit.value.datatype === nextEdit.value.datatype &&
typeof lastEdit.value.value === typeof nextEdit.value.value) {
lastEdit.action = 'multi-insert'
if (nextEdit.value.datatype) lastEdit.datatype = nextEdit.value.datatype
lastEdit.values = [lastEdit.value.value, nextEdit.value.value]
delete lastEdit.value
delete lastEdit.opId
} else if (lastEdit.action === 'multi-insert' && nextEdit.action === 'insert' &&
lastEdit.index + lastEdit.values.length === nextEdit.index &&
nextEdit.value.type === 'value' && nextEdit.elemId === nextEdit.opId &&
opIdDelta(lastEdit.elemId, nextEdit.elemId, lastEdit.values.length) &&
lastEdit.datatype === nextEdit.value.datatype &&
typeof lastEdit.values[0] === typeof nextEdit.value.value) {
lastEdit.values.push(nextEdit.value.value)
} else if (lastEdit.action === 'remove' && nextEdit.action === 'remove' &&
lastEdit.index === nextEdit.index) {
lastEdit.count += nextEdit.count
} else {
existingEdits.push(nextEdit)
}
}