void addToStack(@NotNull DocumentReference reference, @NotNull ImmutableActionChangeRange changeRange) {
    UndoRedoList<ImmutableActionChangeRange> stack = getStack(reference);
    trimInvalid(stack);
    if (!isValid(changeRange)) {
      if (stack.isEmpty()) {
        return;  // No need to add invalid change at the beginning of stack since it will be trimmed anyway
      }
      else {
        ImmutableActionChangeRange lastRange = stack.getLast();
        if (!isValid(changeRange) && isRolledBackBy(lastRange, changeRange)) {
          stack.removeLast();
          return;
        }
      }
    }
    stack.add(changeRange);
  }
void addToStack(@NotNull DocumentReference reference, @NotNull ImmutableActionChangeRange changeRange)