adjustCursor = function (c, range) {
      if (c.selectionStart >= range.selectionEnd) {
        // cursor after range
        return [range.result.offset, range.result.offset];
      } else if (c.selectionStart >= range.selectionStart && c.selectionStart <= range.selectionEnd) {
        // cursor start within range
        if (c.selectionEnd <= range.selectionEnd) {
          // cursor entirely inside of range
          return [
            range.selectionStart - c.selectionStart,
            range.selectionStart - c.selectionEnd + range.result.selectRelative[0]
          ];
        }  else {
          // cursor end outside of range
          return [
            range.selectionStart - c.selectionStart,
            range.result.offset
          ];
        }
      } else if (c.selectionStart < range.selectionStart && c.selectionEnd >= range.selectionStart) {
        if (c.selectionEnd <= range.selectionEnd) {
          // cursor start before range, end in range
          return [
            0,
            range.selectionStart - c.selectionEnd + range.result.selectRelative[0]
          ];
        } else {
          // cursor start before range, end after range
          return [
            0,
            range.result.offset
          ];
        }
      } else {
        return [0, 0];
      }
    }
Emulate a user action. Use this when emulation mode is enabled.
Will throw an error if not in emulation mode.
Specific user actions are available on the `CPHCursor`
object, prefixed with the word `calculate`.
@param {string} name The name of the user action to dispatch