Repository: quilljs/quill
File: core/editor.js (JavaScript)

Code before:
  switch (type) {
    case 'checked':
      return [tag, ' data-list="checked"'];
    case 'unchecked':
      return [tag, ' data-list="unchecked"'];
    default:
      return [tag, ''];
  }
}

function normalizeDelta(delta) {
  return delta.reduce((normalizedDelta, op) => {
    if (typeof op.insert === 'string') {
      const text = op.insert.replace(/\r\n/g, '\n').replace(/\r/g, '\n');
      return normalizedDelta.insert(text, op.attributes);
    }
    return normalizedDelta.push(op);
  }, new Delta());
}

function splitDelta(delta, index) {
  return [delta.slice(0, index), delta.slice(index)];
}

function diffDeltas(oldDelta, newDelta, selectionInfo = undefined) {
  if (selectionInfo) {
    // generate better diffs than Delta#diff by taking into account the
    // old and new selection.  for example, a text change from "xxx" to "xx"
    // could be a delete or forwards-delete of any one of the x's, or the
    // result of selecting two of the x's and typing "x".
    const [oldSelection, newSelection] = selectionInfo;
    const oldDeltaLength = oldDelta.length();
    const newDeltaLength = newDelta.length();
    if (oldSelection.length === 0 && newSelection.length === 0) {
      const oldCursor = oldSelection.index;
      const newCursor = newSelection.index;
      const [oldBefore, oldAfter] = splitDelta(oldDelta, oldCursor);
      const [newBefore, newAfter] = splitDelta(newDelta, newCursor);
      if (equal(oldAfter, newAfter)) {
        const prefixLength = Math.min(oldCursor, newCursor);
        const [oldPrefix, oldMiddle] = splitDelta(oldBefore, prefixLength);
        const [newPrefix, newMiddle] = splitDelta(newBefore, prefixLength);
        if (equal(oldPrefix, newPrefix)) {
          // insert or delete right before cursor
          return new Delta()
            .retain(prefixLength)
            .concat(oldMiddle.diff(newMiddle));
        }
      } else if (equal(oldBefore, newBefore)) {
        const suffixLength = Math.min(
          oldDeltaLength - oldCursor,

Review comment (suggestion):
Since there's no substantial else branch we can we instead check the opposite and return right away and save an indent on a lot of code? Also the inner if + else if both check for the same second condition which could be made more obvious by checking outside/immediately too so adding both of this together we could do something like:

```js
const [oldSelection, newSelection] = selectionInfo || [];
if (selectionInfo == null || newSelection.length > 0) {
  return oldDelta.diff(newDelta);
}
```

Code after:
    default:
      return [tag, ''];
  }
}

function normalizeDelta(delta) {
  return delta.reduce((normalizedDelta, op) => {
    if (typeof op.insert === 'string') {
      const text = op.insert.replace(/\r\n/g, '\n').replace(/\r/g, '\n');
      return normalizedDelta.insert(text, op.attributes);
    }
    return normalizedDelta.push(op);
  }, new Delta());
}

function splitDelta(delta, index) {
  return [delta.slice(0, index), delta.slice(index)];
}

function diffDeltas(oldDelta, newDelta, selectionInfo = undefined) {
  if (selectionInfo == null) {
    return oldDelta.diff(newDelta);
  }

  // generate better diffs than Delta#diff by taking into account the
  // old and new selection.  for example, a text change from "xxx" to "xx"
  // could be a delete or forwards-delete of any one of the x's, or the
  // result of selecting two of the x's and typing "x".
  const [oldSelection, newSelection] = selectionInfo;
  const oldDeltaLength = oldDelta.length();
  const newDeltaLength = newDelta.length();
  if (oldSelection.length === 0 && newSelection.length === 0) {
    // see if we have an insert or delete before or after cursor
    const oldCursor = oldSelection.index;
    const newCursor = newSelection.index;
    const [oldBefore, oldAfter] = splitDelta(oldDelta, oldCursor);
    const [newBefore, newAfter] = splitDelta(newDelta, newCursor);
    if (equal(oldAfter, newAfter)) {
      const prefixLength = Math.min(oldCursor, newCursor);
      const [oldPrefix, oldMiddle] = splitDelta(oldBefore, prefixLength);
      const [newPrefix, newMiddle] = splitDelta(newBefore, prefixLength);
      if (equal(oldPrefix, newPrefix)) {
        // insert or delete right before cursor
        return new Delta()
          .retain(prefixLength)
          .concat(oldMiddle.diff(newMiddle));
      }
    } else if (equal(oldBefore, newBefore)) {
      const suffixLength = Math.min(
        oldDeltaLength - oldCursor,
        newDeltaLength - newCursor,