← Guides EVOLution
Loaded

Cumulative Final · All units Study Guide

BIOL 4230 · Evolution · Cumulative Final · All units — Final exam Mon May 4, 2026 · 5–7 PM · Dr. Travis Robbins
Lectures: L01 · L02 · L03 · L04 · L05 · L07 · L08 · L09 · L11 · L12 · L13 · L14 · L15 · L16 · L17 · L18 · L19 · L20

This guide is fully editable — type anywhere, format with the toolbar, and your edits autosave to this browser. Reset restores the seeded content. Print to PDF (8.5×11 portrait) anytime.

L01 · What Is Evolution? Course Intro (Ch 1)

First lecture frames evolution as the unifying theory of biology — a process of heritable change in populations over generations — and previews the four mechanisms (selection, drift, gene flow, mutation) the rest of the course will dissect.

§A — Defining evolution

Evolution is descent with modification — change in the heritable traits of populations across generations. It is a population-level, multi-generational phenomenon, not something that happens to an individual.

Key points

Key terms

Exam traps
  • An individual cannot 'evolve' — even if they change during their lifetime, evolution requires change across generations in a population.
  • If trait differences are NOT heritable (e.g., purely environmental), selection on those traits produces no evolutionary change.

§B — Why evolution unifies biology

Dobzhansky's 1973 essay — 'Nothing in biology makes sense except in the light of evolution' — captures the role evolution plays as the explanatory glue across every biological subdiscipline.

Key points

Key terms

Exam traps
  • 'Adaptation' has two meanings — a trait (the noun) AND the process that produces it (the verb). Context matters.

§C — The four evolutionary mechanisms (preview)

Four forces change allele frequencies. The course spends the next several lectures dissecting each one in turn.

Key points

Key terms

Exam traps
  • Mutation is RANDOM with respect to fitness (it doesn't 'know' what's useful), but selection acting on the resulting variation is NON-random.
  • Drift and selection both change allele frequencies — but only selection systematically increases fitness.

L02 · Evolutionary Thinking — From Pre-Darwinian Worldviews to Natural Selection (Ch 2)

How biologists came to think about life as a tree, not a ladder. This lecture traces the conceptual road from the Great Chain of Being to Darwin and Wallace, and frames the scientific method (hypothesis vs. theory) that lets evolutionary claims be tested.

§A — The Great Chain of Being and pre-Darwinian thinking

Before Darwin, the dominant Western view of life was the Scala Naturae — a fixed hierarchical ladder with humans at the top and 'lower' organisms at the bottom. Species were considered immutable; extinction was not yet recognized as a real phenomenon.

Key points

Key terms

Exam traps
  • The Great Chain of Being is NOT an evolutionary tree — it is a fixed ladder with no branching, no common ancestry, and no extinction.
  • Don't confuse the Chain of Being's 'progression toward humans' with evolution. Evolution does not progress toward any goal.

§B — Extinction recognized — William Smith and stratigraphy

The realization that whole groups of organisms had disappeared came from geology. William Smith showed that fossil sequences in rock layers had a consistent pattern across geography — and that some forms simply stopped appearing in younger rock.

Key points

Key terms

Exam traps
  • The study guide explicitly flags William Smith's role in establishing extinction — be ready to attribute him.
  • Faunal succession is descriptive (which fossils where) — it doesn't on its own explain WHY species disappeared. Extinction as a concept comes from observing the pattern.

§C — Lamarck, Lyell, and the road to Darwin

Several thinkers helped clear the conceptual ground before Darwin. Lamarck proposed an evolutionary mechanism (wrong about the details). Lyell argued for deep time and gradual geological change. Both shaped how Darwin framed natural selection.

Key points

Key terms

Exam traps
  • Lamarck is famous as a wrong example, but the study guide calls for matching him to 'inheritance of acquired traits.' Don't dismiss him without naming his contribution.
  • Lyell was a geologist, not an evolutionary biologist. His contribution to evolution was indirect — providing deep time as a backdrop.

§D — Darwin, Wallace, and natural selection

Darwin's voyage on the Beagle (1831–1836) and decades of subsequent work led him to natural selection. Alfred Russel Wallace independently arrived at the same idea — and his 1858 letter is what finally pushed Darwin to publish.

Key points

Key terms

Exam traps
  • The study guide explicitly tests: 'identifying which naturalist spurred Darwin to make his work public' — that's WALLACE, via his 1858 letter.
  • Natural selection requires variation, heritability, AND differential reproductive success. All three. Missing any one and the population doesn't evolve.

§E — Hypotheses vs. theories — the scientific method

Lay usage of 'theory' often means 'guess,' but in science it means something quite different. Distinguishing hypothesis from theory is a small but reliably testable item.

Key points

Key terms

Exam traps
  • 'Theory' in everyday language ≠ 'theory' in science. Saying evolution is 'just a theory' confuses the two senses.
  • A good hypothesis says what observations would falsify it. 'Evolution happens' is too broad to be a hypothesis; 'antibiotic resistance increases when antibiotics are widely used' is testable.

L03 · Genes and Heritable Variation (Ch 5)

Evolution requires heritable variation. This lecture is the genetics-and-genomics foundation: what genes ARE, how genomes are built, how alleles differ in their phenotypic effects, and how gene expression is regulated at multiple levels.

§A — Genome architecture — coding vs. noncoding DNA

Eukaryotic genomes are mostly NOT made of protein-coding genes. The bulk is noncoding DNA — pseudogenes, mobile elements, regulatory sequences, and stretches with no known function. This matters because evolution acts on genome content as a whole.

Key points

Key terms

Exam traps
  • Genome size ≠ gene count ≠ complexity. The study guide flags this directly: 'genome size does not necessarily correlate with organismal complexity.'
  • Pseudogenes ARE part of the genome — they are real DNA, just not functional. Don't exclude them when listing genome contents.

§B — Levels of gene expression regulation

Cells regulate gene expression at multiple stages — pre-transcriptional, transcriptional, post-transcriptional, and post-translational. Knowing which mechanism acts at which level is a core test item.

Key points

Key terms

Exam traps
  • DNA methylation = PRE-transcriptional (controls access). MicroRNA = POST-transcriptional (degrades mRNAs after they're made). Don't mix them up.
  • Phosphorylation can occur during transcription factor activation (transcriptional) or as a post-translational modification of any protein. Context tells you which level.

§C — Alleles — dominant, recessive, additive

Alleles are alternative versions of a gene at the same locus. How they interact with one another (dominance) — and how the homozygote/heterozygote phenotypes relate — sets how quickly selection can change allele frequencies.

Key points

Key terms

Exam traps
  • Beneficial RECESSIVE alleles increase slowly when rare (most are in Aa heterozygotes, hidden from selection). Beneficial DOMINANT alleles increase quickly when rare. Selection efficiency depends on dominance.
  • Don't confuse 'additive' (linear dose-response across copies) with 'codominant' (both alleles' phenotypes are visible in the heterozygote, but not necessarily linearly intermediate).

§D — Mutation as the source of new variation

Mutation is the ULTIMATE source of new genetic variation. Selection cannot create new alleles — it can only sort among existing variants. Mutation is random with respect to fitness.

Key points

Key terms

Exam traps
  • Mutation is random WITH RESPECT TO FITNESS. Mutation rates can vary across the genome (hotspots) and respond to environmental stressors — but the randomness referred to is about fitness-direction, not uniform per-base probability.
  • Selection requires variation; mutation generates it. Without mutation, selection eventually exhausts genetic variation.

L04 · Genetic Evolution in Populations — Hardy-Weinberg (Ch 6)

Hardy-Weinberg equilibrium is the null model of population genetics. It predicts genotype frequencies from allele frequencies in an idealized non-evolving population, so any deviation tells you something is going on (selection, drift, mutation, gene flow, or non-random mating).

§A — Allele frequencies vs genotype frequencies

An allele frequency is the proportion of a given allele at a locus across the whole population's gene pool. Genotype frequencies are the proportions of homozygotes and heterozygotes.

Key points

Key terms

Exam traps
  • Don't confuse allele counts with individual counts — each diploid individual contributes TWO allele copies.
  • Heterozygotes contribute ONE A and ONE a to the allele tally, not two of one.

§B — The Hardy-Weinberg equation

Under five idealizing assumptions, expected genotype frequencies are p², 2pq, q². The cross-multiplication comes from random union of gametes — Punnett-square logic at the population level.

Key points

Key terms

Exam traps
  • Hardy-Weinberg gives EXPECTED genotype frequencies under the null. If observed frequencies differ, that's evidence the population is NOT in HWE — i.e., one or more forces are acting.
  • HWE is achieved in ONE generation of random mating from any starting genotype frequencies (allele freq p stays the same; genotype freq snaps to p²/2pq/q²).

§C — Detecting deviations and what they mean

Excess homozygotes vs. excess heterozygotes are diagnostic of different evolutionary processes. Spotting and interpreting deviations is a core exam skill.

Key points

Key terms

Exam traps
  • Selection AGAINST the recessive homozygote (aa) makes a slow change because most a alleles hide in heterozygotes — selection on rare recessives is inefficient.
  • Inbreeding does NOT change allele frequencies on its own — it only changes genotype frequencies (more homozygotes, fewer heterozygotes).

§D — Worked computation pattern

Exam questions often hand you genotype counts and ask you to compute allele frequencies, then expected genotype frequencies under HWE, then compare to observed.

Key points

Exam traps
  • Common arithmetic slip: forgetting to multiply expected genotype FREQUENCIES by N (population size) when comparing to observed COUNTS.
  • If only allele frequencies are given, you cannot detect HWE deviations — you need genotype counts.

L05 · Quantitative Genetics, Selection, and Plasticity (Ch 7)

How traits with continuous variation (height, milk yield, beak depth) evolve. This lecture covers phenotypic variance partitioning, heritability, the breeder's equation, and phenotypic plasticity — the ways environment shapes phenotype without changing genotype.

§A — Quantitative traits and partitioning phenotypic variance

Quantitative traits are continuously varying (height, mass, fitness components) — many genes plus environment. The total phenotypic variance V_P can be decomposed into components, each with a different evolutionary meaning.

Key points

Key terms

Exam traps
  • Only V_A responds predictably to selection. V_D and V_I get reshuffled by recombination each generation, so selection on them produces inconsistent gains.
  • The study guide explicitly asks for the V_P expression — be ready to write it: V_P = V_A + V_D + V_I + V_E.

§B — Heritability — broad-sense vs. narrow-sense

Heritability is the fraction of phenotypic variance attributable to genetic causes. The narrow-sense version (h²) — using only V_A — is what predicts response to selection.

Key points

Key terms

Exam traps
  • h² (lowercase, narrow-sense) ≠ H² (uppercase, broad-sense). The study guide tests h² because it's the one that predicts evolution.
  • Heritability is population-and-environment specific. A trait with h² = 0.6 in one population can have h² = 0.2 in another. Don't quote heritability values as universal facts.

§C — The breeder's equation — predicting response to selection

The breeder's equation R = h² · S links heritability to selection differential to predict the per-generation response to selection. It is the central equation of quantitative genetics.

Key points

Key terms

Exam traps
  • If you select strongly (large S) but h² is near zero, the population doesn't evolve. Heritability is the gating factor.
  • The breeder's equation works for ONE generation at a time. Iterating across generations requires knowing how V_A and h² change as allele frequencies shift (they don't stay constant).

§D — Phenotypic plasticity and reaction norms

A single genotype can produce different phenotypes in different environments. Phenotypic plasticity is the rule, not the exception, and the patterns reveal whether plasticity itself can evolve.

Key points

Key terms

Exam traps
  • Sloped reaction norms = plasticity. Non-parallel reaction norms = G×E. The study guide asks about interpreting these graphs.
  • Plasticity is itself heritable and can evolve. A 'plastic' trait isn't the same as a 'non-genetic' trait — the capacity to be plastic is genetic.

§E — Selection vs. evolution — a recurring distinction

Selection ACTING on a trait does not guarantee EVOLUTION. The link is heritability. This is the integrative concept the study guide returns to repeatedly.

Key points

Exam traps
  • Common exam scenario: selection clearly happens (some individuals reproduce more than others) but the trait is environmentally determined → NO evolutionary response. R = h² · S = 0.
  • Selection is a within-generation process. Evolution is a between-generation outcome that requires heritability.

L07 · Empirical Studies of Natural Selection (Ch 8)

How biologists actually MEASURE natural selection in the wild — landmark long-term studies that move 'selection' from theory to observation. Grants' finches, peppered moths, and similar systems are the empirical canon.

§A — How selection is measured in nature

To demonstrate natural selection in the field, you need to (1) measure heritable variation in a trait, (2) measure differential survival or reproduction associated with that variation, and (3) ideally see allele-frequency change across generations.

Key points

Key terms

Exam traps
  • Selection in the field can produce TINY per-generation changes that nonetheless add up over decades. Don't dismiss small year-on-year shifts.
  • Without heritability data, observed differential reproduction is selection but doesn't predict evolution.

§B — Grants' Galápagos finches

Peter and Rosemary Grant's decades-long study of medium ground finches (Geospiza fortis) on Daphne Major is the gold standard of natural selection in action.

Key points

Key terms

Exam traps
  • The classic finch result is one-direction selection (deeper beaks) followed by reversal in different conditions. Selection can flip direction.
  • The Grants observed evolution over a few generations — not 'gradualism takes millions of years' as caricatured. Natural selection can act rapidly given strong pressure.

§C — Peppered moths and industrial melanism

Peppered moths (Biston betularia) shifted from light to dark forms during the Industrial Revolution and back again with pollution control. The textbook case of rapid microevolution under human-caused selection.

Key points

Key terms

Exam traps
  • The peppered moth case is sometimes attacked as bad evidence; modern replication of Kettlewell's experiments confirms differential predation does drive the morph frequencies.
  • The selective agent is bird predation on resting moths — not direct toxicity of pollutants.

§D — Other documented examples — flu, antibiotics, domestication

Beyond classic natural systems, human activities provide many real-time tests of selection: pathogens evolving resistance, domesticated species evolving under artificial selection.

Key points

Key terms

Exam traps
  • Antibiotic resistance is NOT caused by the antibiotic mutating bacteria. The mutations occur randomly; the antibiotic selects existing variants.
  • Artificial selection follows the same logic as natural selection — the only difference is who/what is doing the selecting.

L08 · Complex Adaptations (Ch 10)

How complex traits — eyes, wings, body plans — evolve through stepwise mutations, regulatory changes, and gene-network conservation. This lecture is the EVO-DEVO chapter, integrating molecular biology with classical evolutionary thinking.

§A — Adaptation as both trait and process

The word 'adaptation' has two meanings: a trait that has been shaped by past selection, AND the process by which selection produces such traits. Complex adaptations build incrementally — they do not appear in their finished form.

Key points

Key terms

Exam traps
  • The classic 'half an eye is useless' objection ignores that early eyes are not failed full eyes — they are simpler light-detecting structures with their own value.
  • Selection works on what's available. A trait can be 'good enough' rather than perfect — historical contingency leaves limits.

§B — Evolution of the vertebrate eye — gradual stepwise model

The vertebrate eye is the textbook example of complex adaptation evolving through functional intermediates. Each step (light-sensitive patch → cup → pinhole → lensed eye) is itself useful.

Key points

Key terms

Exam traps
  • The vertebrate camera eye and the cephalopod camera eye look superficially similar but evolved independently — convergent, not homologous.
  • Each eye-evolution stage is documented in a living organism today (flatworm patches, Nautilus pinhole, etc.). The intermediates are not hypothetical.

§C — Regulatory networks and gene duplication

A lot of evolutionary novelty comes from RE-WIRING existing genes rather than inventing new ones. Mutations in regulatory regions, gene duplication followed by sub- or neofunctionalization, and changes in expression timing/location all reshape phenotype without changing the underlying protein-coding repertoire.

Key points

Key terms

Exam traps
  • Cis-regulatory evolution is a major route to morphological novelty — Hox-gene expression changes reshape body plans without changing the Hox proteins themselves.
  • Don't confuse subfunctionalization with neofunctionalization. Sub: each copy does part of the original. Neo: one copy gains a new function.

§D — Heterochrony — changes in developmental timing

Many morphological differences across species reflect changes in WHEN developmental processes occur, not WHAT they do. Speeding up, slowing down, or shifting the onset of a process produces dramatically different adult forms.

Key points

Key terms

Exam traps
  • Heterochrony explains a lot of variation among closely related species without invoking many new genes.
  • Don't conflate heterochrony with heterotopy (changes in WHERE in the body something develops). Different concept, often paired.

§E — Hox genes and conserved developmental networks

Hox genes encode transcription factors that pattern the anterior-posterior axis of bilaterian animals. They are deeply conserved across phyla — the same Hox toolkit patterns flies, mice, and humans.

Key points

Key terms

Exam traps
  • Hox-gene CONSERVATION across phyla is the headline. Differences in body plan come largely from differences in REGULATION, not from new Hox proteins.
  • Don't say Hox genes 'cause' segments. They specify segment IDENTITY — what each segment becomes — given an underlying segmentation process.

§F — Imperfect adaptation — limits and constraints

Selection produces traits that are 'good enough,' not optimal. Historical legacy, developmental constraints, and trade-offs leave fingerprints of imperfection — and those imperfections are often the strongest evidence of evolution.

Key points

Key terms

Exam traps
  • Imperfections are powerful evidence of evolution. A designed system would not have a blind spot; an evolved one inherits its 'mistakes.'
  • 'Good enough' is the right framing — selection lifts fitness, but is not an optimization algorithm with foresight.

L09 · Coevolution (Ch 15)

Coevolution is reciprocal evolutionary change in two interacting species — each lineage's adaptations are evolutionary responses to the other. It produces arms races, mutualisms, and the geographic mosaic of selection.

§A — Defining reciprocal coevolution

Coevolution is not just any pair of species coexisting — it requires that adaptations in one lineage drive adaptive responses in the other, in a feedback loop.

Key points

Key terms

Exam traps
  • Mere ecological association ≠ coevolution. The textbook bar is: changes in species A drive changes in species B, which drive further changes in A.
  • Convergent evolution (similar solutions in unrelated lineages) is NOT coevolution — there's no reciprocal feedback.

§B — Antagonistic arms races

When predator-prey or host-parasite interactions persist, each side evolves countermeasures, which selects for new adaptations in the other side, in an open-ended escalation.

Key points

Key terms

Exam traps
  • Arms races don't always escalate forever — fitness costs (e.g., snake speed cost of TTX resistance) can cap the escalation.
  • Variation across geography is the key signature of a true arms race; uniform 'one-size-fits-all' adaptations argue against ongoing coevolution.

§C — Mutualistic coevolution

Mutualisms are coevolutionary too: each partner's traits are adapted to the other, and selection on one drives change in the other in a cooperative direction.

Key points

Key terms

Exam traps
  • Mutualists often cheat — selection favors taking benefits without paying costs. Stable mutualisms typically have enforcement mechanisms.
  • Mutualism is not 'cooperation for the good of the species' — each partner is selected for individual fitness; mutual benefit is a coincidence of interests.

§D — Mimicry — Batesian vs. Müllerian

Mimicry is a coevolutionary product where one species' phenotype evolves to resemble another. The two flavors differ in who pays the cost.

Key points

Key terms

Exam traps
  • Batesian mimicry breaks down at high mimic-to-model ratios — predators encounter the harmless mimic too often and stop avoiding the warning signal.
  • Müllerian mimicry is technically convergent evolution AND coevolution — both species evolve toward each other's signal.

§E — Geographic Mosaic Theory of Coevolution

Thompson's framework: coevolutionary outcomes vary across geography because local ecological conditions tilt the cost/benefit balance differently in different places.

Key points

Key terms

Exam traps
  • Mosaic theory predicts trait MISMATCH in some areas — this is evidence FOR ongoing coevolution, not against it.
  • Don't confuse the geographic mosaic with simple local adaptation; mosaic theory specifically requires reciprocal feedback between species.

L11 · Sex and Sexual Selection (Ch 11)

Why does sex exist at all, given its costs? Once it exists, why do males and females differ so dramatically? This lecture covers the evolution of sexual reproduction, the origin of anisogamy, and the consequences — sexual selection, sexual conflict, sperm competition.

§A — The cost of sex and why sex evolved anyway

Sexual reproduction has obvious costs (the 'twofold cost of males,' searching for mates, recombination breaking up good gene combinations) — yet sex is widespread. The benefits must outweigh these costs.

Key points

Key terms

Exam traps
  • The 'twofold cost' is sometimes phrased as the cost of MALES, sometimes the cost of SEX. The cost is real either way — sexual mothers transmit half the gene copies per offspring vs. asexual.
  • Muller's ratchet specifically requires that recombination be ABSENT. Bacteria recombine via horizontal gene transfer and can purge mutations by other routes.

§B — Anisogamy — the foundation of male and female

ANISOGAMY = unequal gamete sizes. Females (by definition) produce few large gametes (eggs); males produce many small gametes (sperm). This asymmetry is the foundation of nearly all sex differences.

Key points

Key terms

Exam traps
  • Sex is defined by GAMETE SIZE, not by secondary sex characteristics, behavior, or chromosomes. Don't define 'female' as 'the one that nurtures' — that's downstream of anisogamy.
  • Anisogamy is not 'why' sex exists; it's a feature of HOW sex is organized once it exists.

§C — Sexual selection — Darwin's second mechanism

Sexual selection is selection on traits that increase MATING success rather than survival. It explains otherwise-puzzling traits (peacock tails, antlers) that reduce survival.

Key points

Key terms

Exam traps
  • Sexual selection IS a form of natural selection — Darwin distinguished them but they share the same logic of differential reproduction.
  • Sexually selected traits (peacock tails) often REDUCE survival. Their fitness gain comes from mating, which more than offsets the survival cost.

§D — Sexual conflict and sperm competition

Male and female evolutionary interests often diverge. Sexual CONFLICT — selection pressures pulling males and females in different directions — drives much of the elaborate biology of mating.

Key points

Key terms

Exam traps
  • Sexual conflict is INTRA-species coevolution — males and females are members of the same species and yet are evolutionary antagonists.
  • Sperm competition implies polyandry (multiple mating by females). In strictly monogamous species, sperm competition is weak.

L12 · Life History Evolution (Ch 12)

Life history is the schedule of an organism's birth, growth, reproduction, and death. Selection cannot maximize all these at once — trade-offs between traits force compromises, and the form those compromises take depends on the environment.

§A — Trade-offs in energy allocation

An organism has finite resources and time. Energy spent on growth cannot be spent on reproduction; reproduction now reduces resources available for survival and future reproduction.

Key points

Key terms

Exam traps
  • Trade-offs are physical/physiological — they are not optional. Selection works WITHIN trade-offs to optimize, not to escape them.
  • Don't expect organisms to maximize one fitness component (e.g., longevity). Selection maximizes lifetime reproductive success, integrated over all life-history traits.

§B — Extrinsic mortality and life-history strategies

Extrinsic mortality — the rate at which adults die from external causes (predation, disease) — is the single most important determinant of optimal life-history strategy.

Key points

Key terms

Exam traps
  • When the study guide asks about predation effects, the answer is usually: high predation → early/fast reproduction; low predation → delayed/slow reproduction.
  • Extrinsic mortality affects optimal age at maturity, even if intrinsic survival is high.

§C — Theories of senescence — why we age

Why doesn't selection prevent aging? Two main answers, both rooted in the fact that selection becomes weaker at older ages.

Key points

Key terms

Exam traps
  • Antagonistic pleiotropy is a single-gene story (one gene, two effects at different ages). Mutation accumulation is a many-gene story (many late-acting mutations escape selection).
  • 'Why we age' has multiple non-exclusive answers — be ready to name and distinguish at least two of the three theories.

§D — Age at maturity and offspring size

When to start reproducing, and how to package each offspring, are central life-history decisions. Both depend on environmental risk and resource availability.

Key points

Key terms

Exam traps
  • r/K is a useful heuristic but not a strict dichotomy. Many species are intermediate. Modern life-history theory uses continuous variables.
  • Earlier maturity does NOT always mean smaller offspring; the trade-off is about TOTAL reproductive investment, not necessarily individual offspring size.

§E — Case study — Seychelles warblers

The Seychelles warbler (Acrocephalus sechellensis) population on Cousin Island provides one of the best documented life-history datasets, including sex-biased dispersal driven by territory quality.

Key points

Key terms

Exam traps
  • Sex-biased dispersal in Seychelles warblers is FEMALE-PHILOPATRIC (females stay on good territories, males disperse). The direction of bias is testable.
  • Helping is not pure altruism — helpers gain inclusive fitness through helping kin and may inherit territories later.

L13 · Evolution of Social Behavior (Ch 16)

How can selection favor cooperative or self-sacrificing behavior when those behaviors apparently lower the actor's fitness? The answer — kin selection, inclusive fitness, evolutionarily stable strategies — is a foundational result in modern evolutionary biology.

§A — Individual vs. group selection

An old idea: traits evolve 'for the good of the species' or 'good of the group.' Modern evolutionary biology rejects naïve group selection — selection acts predominantly at the level of individuals (or genes), and selfish individuals usually outcompete cooperative ones.

Key points

Key terms

Exam traps
  • 'Good of the species' is a non-explanation. Always ask: what's in it for the individual (or the gene)?
  • Group selection isn't strictly impossible, but it's overwhelmed by individual selection in nearly all real-world cases.

§B — Kin selection and inclusive fitness

Hamilton's insight: an altruistic gene can spread if its bearers help GENETIC RELATIVES, who share copies of the gene. The propagation of the gene matters, not the survival of the individual.

Key points

Key terms

Exam traps
  • Hamilton's rule is rB > C, NOT B > C. Forgetting the r is the classic error.
  • Helping random strangers does not satisfy Hamilton's rule (r = 0). Apparent altruism toward strangers usually involves reciprocity, reputation, or other mechanisms.

§C — Evolutionarily stable strategies (ESS)

An ESS is a behavioral strategy that, once common in a population, cannot be invaded by a rare alternative. ESS reasoning predicts which behaviors persist under frequency-dependent selection.

Key points

Key terms

Exam traps
  • An ESS is not necessarily the BEST strategy on average — it's the strategy that can't be displaced once common. Mixed ESS solutions are common.
  • Frequency-dependent selection can MAINTAIN diversity at equilibrium — different strategies coexist because each is favored when rare.

§D — Side-blotched lizards — rock-paper-scissors in nature

Male side-blotched lizards (Uta stansburiana) come in three throat-color morphs that play a rock-paper-scissors mating game — a real-world demonstration of frequency-dependent ESS dynamics.

Key points

Key terms

Exam traps
  • The 'rock-paper-scissors' framing: Orange > Blue, Blue > Yellow, Yellow > Orange. Cyclic dominance, not one winner.
  • This is a real demonstration of NEGATIVE frequency-dependent selection — each morph is favored when rare, disadvantaged when common.

§E — Cooperation among non-kin — reciprocity, reputation, byproducts

Cooperation among unrelated individuals does occur. The mechanisms are different from kin-selected altruism — reciprocity, reputation, partner choice, or mutual benefit.

Key points

Key terms

Exam traps
  • Reciprocity requires REPEATED INTERACTION — it doesn't work in one-shot games or anonymous encounters.
  • Cooperation among non-kin is often unstable; cheating invades unless mechanisms exist to detect and punish defectors.

L14 · History of Life (Ch 3)

A 4-billion-year overview of life on Earth — when, where, and roughly how. The lecture covers Earth's age, key evolutionary milestones (origin of life, photosynthesis, eukaryotes, multicellularity, Cambrian explosion), mass extinctions, and the dating tools that anchor it all.

§A — Earth's age and dating methods

Earth is ~4.568 billion years old. We know this from radiometric dating of Earth and meteorite materials. Dating life's milestones depends on the same physics — measuring ratios of radioactive isotopes in rocks.

Key points

Key terms

Exam traps
  • Carbon-14 dating only works back ~50,000 years (5 half-lives × 5,730 yr ≈ 28k yr; method becomes unreliable beyond that). For deep time, you need U-Pb, K-Ar, etc.
  • Earth's age is ~4.568 billion years — close to but distinct from the universe's age (~13.8 Gyr) or the age of the oldest rocks on Earth (~4.0 Gyr).

§B — Major milestones in life's history

Life appeared early. Then for a couple billion years, very little visible happened. Then in a few hundred million years, all the modern phyla appeared. The timeline matters.

Key points

Key terms

Exam traps
  • The Cambrian explosion is RAPID on a geological timescale (~20 MYR) but is NOT instant. It also represents the appearance of HARD PARTS that fossilize, not necessarily the origin of phyla.
  • Don't confuse the Permian-Triassic extinction (~252 MYA, biggest) with the K-T / K-Pg extinction (~66 MYA, dinosaurs).

§C — Geological time periods to recognize

The study guide explicitly lists Ordovician, Silurian, Devonian, Permian. Be ready to associate each period with its key biological event.

Key points

Key terms

Exam traps
  • The study guide explicitly tests these period-event associations. Memorize the canonical pairings.
  • The Devonian = 'Age of Fishes'; the Permian-Triassic boundary = the largest mass extinction.

§D — Mass extinctions

Five 'Big Five' mass extinctions punctuate the Phanerozoic. Each reset evolutionary trajectories — opening new niches for survivors. Mass extinction is not unidirectional; it shapes which lineages get to radiate next.

Key points

Key terms

Exam traps
  • The study guide directly asks about the K-T boundary's significance — be ready: asteroid impact, end-Cretaceous, non-avian dinosaur extinction, mammal radiation thereafter.
  • K-T (K-Pg) is the dinosaur extinction; the Permian-Triassic is the bigger one. Don't confuse them.

L15 · Phylogenetics and the Tree of Life (Ch 4)

Phylogenetic trees are hypotheses about evolutionary relationships built from shared derived characters. The skill on this exam is reading trees correctly and choosing the right kind of character (synapomorphy, not symplesiomorphy or homoplasy) to define groups.

§A — Reading phylogenetic trees

A phylogenetic tree depicts hypothesized evolutionary relationships among taxa. Tips are extant or extinct organisms; internal nodes are common ancestors; branches represent lineages over time.

Key points

Key terms

Exam traps
  • Visual proximity on the page does NOT equal evolutionary closeness — trees can be drawn with branches in any rotation.
  • Don't assume tips on adjacent branches are sister groups; trace back to the node and see what it joins.

§B — Synapomorphies vs. symplesiomorphies vs. homoplasies

Only SYNAPOMORPHIES — shared derived characters — define monophyletic groups. Symplesiomorphies (shared ancestral traits) and homoplasies (independent acquisitions) mislead.

Key points

Key terms

Exam traps
  • 'Has a backbone' is a synapomorphy of vertebrates as a whole, but a SYMPLESIOMORPHY for any subgroup (e.g., mammals + birds) — i.e., the same character can play different roles depending on the level you're working at.
  • If two distantly related lineages share a feature, suspect homoplasy — check whether the common ancestor likely had it.

§C — Monophyletic, paraphyletic, polyphyletic

Modern systematics requires named groups to be monophyletic. Para- and polyphyletic groups are rejected because they don't reflect evolutionary history.

Key points

Key terms

Exam traps
  • Birds nest within reptiles — calling 'Reptilia' (without birds) a valid group makes it paraphyletic. Modern usage either includes birds or uses 'Sauropsida'.
  • Polyphyletic groups are diagnosed by SHARED CONVERGENT FEATURES, not common ancestry.

§D — Species concepts

Different species concepts emphasize different criteria. The Biological Species Concept (BSC) is the most famous, but it has limits.

Key points

Key terms

Exam traps
  • The BSC requires reproductive isolation — but two morphologically distinct populations that occasionally hybridize can still be 'good' biological species if hybrids have reduced fitness.
  • Asexual organisms (bacteria, parthenogenetic animals) are not species under the BSC. Use morphology or phylogeny instead.

L16 · Species Concepts and Reproductive Isolation (Ch 13)

What IS a species, exactly? Different concepts emphasize different criteria, each with strengths and limits. This lecture covers species concepts and the reproductive isolation mechanisms — pre- and postzygotic — that keep species apart.

§A — Major species concepts

There is no single universal species definition. The Biological Species Concept dominates animal biology; alternatives handle cases where the BSC fails.

Key points

Key terms

Exam traps
  • The BSC fails for asexual organisms (bacteria, parthenogenetic species) and for fossils — you can't test interbreeding with extinct populations.
  • Different concepts can disagree about what counts as a species in the same case (e.g., a hybridizing species pair). The 'right' concept depends on what you need it for.

§B — Reproductive isolation — prezygotic vs postzygotic

The BSC requires reproductive isolation. Mechanisms split into PREZYGOTIC (preventing zygote formation) and POSTZYGOTIC (acting after zygote formation).

Key points

Key terms

Exam traps
  • Pre-zygotic = before zygote (no successful fertilization). Post-zygotic = after zygote (hybrid problems). The dividing line is fertilization.
  • Hybrid INVIABILITY ≠ hybrid STERILITY. Inviability: hybrids die. Sterility: hybrids live but can't reproduce.

§C — Speciation — how new species arise

Speciation is the evolutionary process by which one species splits into two or more reproductively isolated descendants. Geography is often (but not always) involved.

Key points

Key terms

Exam traps
  • Allopatric is the DEFAULT speciation mode for most animals. Sympatric is rare in animals but more common in plants (polyploidy is sympatric).
  • Reinforcement is a SECONDARY-CONTACT phenomenon — it only operates AFTER initial divergence in allopatry, when populations meet again.

§D — Hybrid zones and viable hybrids

Real populations don't always fit clean species boundaries. Hybrid zones — where two species meet and interbreed — reveal incomplete reproductive isolation.

Key points

Key terms

Exam traps
  • Hybrid existence does NOT disprove species status under the BSC — hybrids with reduced fitness still leave the parental species reproductively isolated in the long run.
  • Hybrid speciation (e.g., in sunflowers) is a real but special case where hybrids form a stable third lineage.

L17 · Biogeography, Speciation, and Extinction (Ch 14)

Why are species where they are? This lecture covers the geographic distribution of life — how dispersal, vicariance, and continental drift shape biodiversity, plus what determines diversity in a given place over time.

§A — What is biogeography?

Biogeography is the study of WHERE species live and WHY. Past geological history (continental drift, glaciation) and ecological factors (climate, dispersal) jointly shape modern distributions.

Key points

Key terms

Exam traps
  • Biogeography unites geology, ecology, and evolution — questions can pull from any of these.
  • Patterns of distribution are clues to history; similar species in distant places may share ancestry (vicariance) or have dispersed.

§B — Dispersal vs. vicariance

Two opposing explanations for why related species are found in different places: organisms moved (dispersal) or the geography moved underneath them (vicariance).

Key points

Key terms

Exam traps
  • Distinguishing dispersal from vicariance requires DATING — vicariant splits should match the geological barrier formation; dispersal splits can be any age.
  • Don't assume vicariance for every pair of similar species on different continents — some are dispersal events (especially birds, oceanic taxa).

§C — Standing diversity and species turnover

STANDING DIVERSITY is how many species are present in a region at one time. TURNOVER is the rate at which species enter (originate, immigrate) and leave (go extinct, emigrate).

Key points

Key terms

Exam traps
  • Standing diversity is a SNAPSHOT; turnover is a RATE. Don't conflate them.
  • Two communities with the same standing diversity can have very different turnover rates.

§D — Mass extinctions and their consequences

Mass extinctions reset the trajectory of life by clearing dominant lineages and opening niches for survivors to radiate into. The Big Five share certain features but had different causes.

Key points

Key terms

Exam traps
  • End-Permian, NOT end-Cretaceous, is the largest mass extinction.
  • The K-Pg extinction is closely linked to the Chicxulub impact, but additional factors (Deccan Trap volcanism) likely contributed.

§E — Adaptive radiations

When a lineage colonizes a new environment or survives a mass extinction, it can rapidly diversify into many species exploiting different niches. Galápagos finches and Hawaiian honeycreepers are classic examples.

Key points

Key terms

Exam traps
  • Adaptive radiation is fast diversification INTO DIFFERENT NICHES — not just speciation in general.
  • Mammalian radiation didn't START at the K-Pg; mammals existed earlier but were small and ecologically restricted. The K-Pg removed dinosaur competitors and let mammals diversify.

L18 · Conservation and Humans as a Selective Force (Ch 8)

Humans are now a dominant evolutionary force — through habitat alteration, hunting, fishing, antibiotic use, and climate change, we are reshaping selection pressures on most species on Earth. This lecture is about that, plus what conservation biology can do.

§A — Humans as selective force

Human activities apply strong, directional selection on countless species. Wherever we hunt, harvest, or otherwise selectively kill or capture organisms, we drive evolutionary change.

Key points

Key terms

Exam traps
  • Human selection is the same evolutionary process as natural selection; we just play the selecting role.
  • Selective harvest can REVERSE pre-existing selection (e.g., natural selection for large body, fishing for small) — populations evolve away from natural-equilibrium phenotypes.

§B — Habitat destruction, fragmentation, and conservation genetics

Habitat loss and fragmentation reduce population sizes and gene flow — making drift stronger, inbreeding more likely, and adaptive evolution slower.

Key points

Key terms

Exam traps
  • Small populations are vulnerable to BOTH demographic and genetic problems. Conservation must address both.
  • Genetic rescue can fail if the introduced population is so distantly related that hybrids are maladapted (outbreeding depression).

§C — Climate change as selective pressure

Anthropogenic climate change is a major and ongoing selective force. Some species track suitable climate by shifting range; others must evolve in place; many will fail to do either fast enough.

Key points

Key terms

Exam traps
  • Species can RESPOND to climate change by shifting range, evolving, going plastic, or going extinct. The mix depends on dispersal ability, generation time, and severity.
  • Phenological shifts driven by climate are evidence of climate change effects on biology, even when range hasn't shifted yet.

§D — Conservation strategies

Conservation biology applies evolutionary thinking to preserving biodiversity. The toolkit ranges from habitat protection to captive breeding to genetic rescue.

Key points

Key terms

Exam traps
  • Conservation is ALWAYS about both populations and the genes within them. A demographically large population with no genetic diversity is still vulnerable.
  • Captive breeding can introduce its own selection pressures (adaptation to captivity) that may reduce wild fitness on release.

L19 · Human Evolution (Ch 17)

Where we came from. The hominin lineage diverged from chimpanzees ~6–7 million years ago in Africa; bipedalism came first, then expanding brain, then long migration out of Africa. This lecture also touches evolutionary medicine — how our evolutionary history shapes modern disease.

§A — The hominin lineage and bipedalism

Humans share a common ancestor with chimpanzees ~6–7 MYA. The first major hominin innovation was BIPEDAL LOCOMOTION, which preceded brain enlargement.

Key points

Key terms

Exam traps
  • The study guide explicitly tests bipedalism: it began ~6–7 MYA. Brain enlargement is later.
  • Sahelanthropus from Chad is the early hominin example the study guide flags. Recognize the Chad connection.

§B — Australopithecines and early Homo

After the earliest hominins, several species of Australopithecus dominated for several million years. Genus Homo appears ~2.5 MYA.

Key points

Key terms

Exam traps
  • Homo erectus is the FIRST hominin to leave Africa, not Homo sapiens.
  • Brain size increased gradually through the hominin lineage; H. erectus had ~1000 cc, H. sapiens ~1350 cc.

§C — Out-of-Africa migrations and Neanderthal/Denisovan introgression

Modern humans (Homo sapiens) originated in Africa, then dispersed worldwide ~70 KYA, encountering and partly interbreeding with archaic populations like Neanderthals and Denisovans.

Key points

Key terms

Exam traps
  • All non-African modern humans carry small amounts of Neanderthal DNA; African populations have very little or none (because the introgression happened after the migration out of Africa).
  • The 'Out of Africa' model is now better called 'Recent African Origin' with admixture — it's not a simple replacement.

§D — Evolutionary medicine — disease in evolutionary context

Many modern health problems make more sense when viewed through an evolutionary lens. Pathogens evolve in response to our defenses; our bodies are evolutionary compromises shaped by ancestral environments different from modern ones.

Key points

Key terms

Exam traps
  • Pathogens evolve. Antibiotic resistance is one application; antigenic shift in flu is another.
  • Evolutionary medicine doesn't say 'we should live like cave-people' — it says understanding the evolutionary mismatch helps explain susceptibility to certain modern diseases.

L20 · Evolutionary Medicine (Ch 18)

Evolution doesn't stop at the species boundary — it explains why we get sick, why pathogens evolve, and why some 'designs' of the human body are flawed. This lecture frames disease, drug resistance, virulence evolution, and modern lifestyle illnesses through an evolutionary lens.

§A — What evolutionary medicine is

Evolutionary medicine applies evolutionary principles to human health. The central insight: many disease vulnerabilities make sense only as products of past selection in environments very different from the one we live in now.

Key points

Key terms

Exam traps
  • Evolutionary medicine doesn't claim modern medicine is wrong — it adds the WHY behind the HOW. Both are needed.
  • 'Why we get sick' is a question with at least six different evolutionary answer categories. Don't reduce all disease to one explanation.

§B — Pathogen evolution and antibiotic resistance

Pathogens evolve fast — large populations, short generation times, strong selection. The most consequential evolutionary process in clinical medicine is antibiotic resistance, but the same logic applies to antiviral resistance, vaccine escape, and host-immune evasion.

Key points

Key terms

Exam traps
  • Antibiotics do NOT cause resistance mutations — they SELECT for already-existing rare resistant variants. Random mutation + non-random selection.
  • Stopping a course early can leave partially-resistant survivors and worsen the resistance problem. Complete the prescribed course (current best evidence is more nuanced than the old 'always finish' rule, but the evolutionary logic still favors fully suppressing the infection).
  • Combination therapy works because the joint probability of multi-drug resistance is the product of single-drug resistance probabilities — for example, 10⁻⁹ × 10⁻⁹ = 10⁻¹⁸ per generation.

§C — Virulence evolution and transmission mode

How harmful (virulent) a pathogen is to its host is itself an evolutionary trait — and it depends on how the pathogen transmits. Mode of transmission shapes the cost-benefit balance for the pathogen.

Key points

Key terms

Exam traps
  • Virulence is NOT 'always' selected to decrease — that old folk-rule (pathogens evolve to be benign) was wrong. The direction depends on transmission mode.
  • Sexually-transmitted, respiratory, and vector-borne pathogens all face DIFFERENT virulence-transmission trade-offs. Predicting virulence evolution requires identifying the transmission route.

§D — Host-pathogen coevolution

Hosts and pathogens are locked in mutual evolutionary arms races. Each side's adaptations select for counter-adaptations in the other — driving rapid evolution on both sides.

Key points

Key terms

Exam traps
  • Sickle-cell anemia is a classic POPULATION-LEVEL example of pathogen-driven host evolution. The allele persists not despite the homozygous cost, but because of the heterozygous benefit.
  • MHC diversity is maintained by BALANCING SELECTION — distinct from directional or stabilizing selection. Rare alleles benefit from being unfamiliar to pathogens.

§E — Mismatch hypothesis — modern environments and chronic disease

Many chronic diseases of the modern industrialized world (obesity, type 2 diabetes, atherosclerosis, certain autoimmune disorders) reflect a mismatch between traits that were adaptive in ancestral environments and the conditions of modern life.

Key points

Key terms

Exam traps
  • Mismatch DOESN'T mean we should live like cave-people; it means understanding our evolutionary history helps explain why certain modern foods and habits are pathogenic.
  • Diseases of old age (most cancers, Alzheimer's) escape selection because they manifest after reproduction. They aren't 'designed' against — selection just can't see them.

§F — Cancer as somatic evolution

Cancer is evolution playing out within an individual body. Cells acquire mutations, some of which give a growth advantage; selection within the body favors those cells; tumors are the result. This view reshapes treatment strategies.

Key points

Key terms

Exam traps
  • Cancer is evolution writ small — the same processes (variation, selection, heritability) operating on cell lineages.
  • Aggressive cancer therapy can SELECT for resistance just like aggressive antibiotic use does. Treatment strategy is also an evolutionary problem.
'; const blob = new Blob([html], {type:'text/html'}); const url = URL.createObjectURL(blob); const a = document.createElement('a'); a.href = url; a.download = 'Final_StudyGuide_BIOL4230.html'; document.body.appendChild(a); a.click(); a.remove(); setTimeout(() => URL.revokeObjectURL(url), 1000); } function applyBlockStyle(){ const el = document.getElementById('styleSelect'); if(!el) return; const tag = el.value; if(!tag) return; try{ document.execCommand('formatBlock', false, '<' + tag + '>'); doc.focus(); markDirty(); }catch(e){ console.warn('formatBlock failed', e); } el.selectedIndex = 0; } function getSelectedBlocks(){ const sel = window.getSelection(); if(!sel || sel.rangeCount === 0) return []; const range = sel.getRangeAt(0); const blocks = new Set(); function climb(node){ while(node && node !== doc){ if(node.nodeType === 1){ const d = getComputedStyle(node).display; if(d === 'block' || d === 'list-item' || /^(P|H[1-6]|LI|BLOCKQUOTE|PRE|FIGURE|TABLE|TR|TD|TH|DIV)$/.test(node.tagName)){ blocks.add(node); return; } } node = node.parentNode; } } climb(range.startContainer); climb(range.endContainer); const it = document.createTreeWalker(doc, NodeFilter.SHOW_ELEMENT, { acceptNode: n => range.intersectsNode(n) ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP }); let n; while((n = it.nextNode())){ const d = getComputedStyle(n).display; if(d === 'block' || d === 'list-item') blocks.add(n); } return Array.from(blocks); } function changeCase(){ const choice = prompt('Change case to:\n 1) UPPERCASE\n 2) lowercase\n 3) Title Case\n 4) Sentence case\nEnter 1, 2, 3, or 4:'); const sel = window.getSelection(); if(!sel || sel.isCollapsed){ alert('Select some text first.'); return; } const text = sel.toString(); let out = text; if(choice === '1') out = text.toUpperCase(); else if(choice === '2') out = text.toLowerCase(); else if(choice === '3') out = text.toLowerCase().replace(/\b([a-z])/g, (m, c) => c.toUpperCase()); else if(choice === '4'){ out = text.toLowerCase().replace(/(^|[.!?]\s+)([a-z])/g, (m, p, c) => p + c.toUpperCase()); } else return; document.execCommand('insertText', false, out); markDirty(); } function applyLineSpacing(){ const el = document.getElementById('lineSpacing'); if(!el || !el.value) return; const v = el.value; getSelectedBlocks().forEach(b => { b.style.lineHeight = v; }); el.selectedIndex = 0; markDirty(); } function colorsEqual(a, b){ if(!a || !b) return false; const ma = ('' + a).match(/\d+/g); const mb = ('' + b).match(/\d+/g); if(!ma || !mb) return false; return ma.slice(0,3).join(',') === mb.slice(0,3).join(','); } function hexToRgb(hex){ const m = hex.replace('#',''); return 'rgb(' + parseInt(m.slice(0,2),16) + ', ' + parseInt(m.slice(2,4),16) + ', ' + parseInt(m.slice(4,6),16) + ')'; } function applyShade(){ const c = document.getElementById('paraShade').value; const target = hexToRgb(c); const blocks = getSelectedBlocks(); if(!blocks.length) return; const allHave = blocks.every(b => colorsEqual(b.style.backgroundColor, target)); blocks.forEach(b => { if(allHave){ b.style.backgroundColor = ''; if(!/pb-/.test(b.className)) b.style.padding = ''; } else { b.style.backgroundColor = c; if(!b.style.padding) b.style.padding = '4px 8px'; } }); markDirty(); } function applyBorder(){ const el = document.getElementById('borderSelect'); if(!el || !el.value) return; const which = el.value; const blocks = getSelectedBlocks(); el.selectedIndex = 0; if(!blocks.length) return; if(which === 'none'){ blocks.forEach(b => b.classList.remove('pb-all','pb-top','pb-bottom','pb-left','pb-right')); } else { const cls = 'pb-' + which; const allHave = blocks.every(b => b.classList.contains(cls)); blocks.forEach(b => { if(allHave){ b.classList.remove(cls); } else { b.classList.remove('pb-all','pb-top','pb-bottom','pb-left','pb-right'); b.classList.add(cls); } }); } markDirty(); } function applyListStyle(){ const el = document.getElementById('listStyleSelect'); if(!el || !el.value) return; const [tag, style] = el.value.split(':'); const cmdName = tag === 'ol' ? 'insertOrderedList' : 'insertUnorderedList'; document.execCommand(cmdName, false, null); const sel = window.getSelection(); if(sel && sel.rangeCount){ let n = sel.getRangeAt(0).startContainer; while(n && n !== doc){ if(n.nodeType === 1 && /^(UL|OL)$/.test(n.tagName)){ n.style.listStyleType = style; break; } n = n.parentNode; } } el.selectedIndex = 0; markDirty(); } /* FIND / REPLACE */ let findHits = []; let findIndex = -1; function clearFindHits(){ doc.querySelectorAll('.find-hit, .find-hit-current').forEach(el => { const parent = el.parentNode; while(el.firstChild) parent.insertBefore(el.firstChild, el); parent.removeChild(el); parent.normalize(); }); findHits = []; findIndex = -1; const cnt = document.getElementById('findCount'); if(cnt) cnt.textContent = ''; } function highlightAll(query){ clearFindHits(); if(!query) return; const re = new RegExp(query.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), 'gi'); const walker = document.createTreeWalker(doc, NodeFilter.SHOW_TEXT, { acceptNode: n => n.parentElement && n.parentElement.closest('.find-hit') ? NodeFilter.FILTER_REJECT : NodeFilter.FILTER_ACCEPT }); const targets = []; let n; while((n = walker.nextNode())){ if(re.test(n.nodeValue)){ re.lastIndex = 0; targets.push(n); } } targets.forEach(node => { const text = node.nodeValue; const frag = document.createDocumentFragment(); let last = 0; let m; const re2 = new RegExp(query.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), 'gi'); while((m = re2.exec(text))){ if(m.index > last) frag.appendChild(document.createTextNode(text.slice(last, m.index))); const span = document.createElement('span'); span.className = 'find-hit'; span.textContent = m[0]; frag.appendChild(span); findHits.push(span); last = m.index + m[0].length; if(m[0].length === 0) re2.lastIndex++; } if(last < text.length) frag.appendChild(document.createTextNode(text.slice(last))); node.parentNode.replaceChild(frag, node); }); const cnt = document.getElementById('findCount'); if(cnt) cnt.textContent = findHits.length ? (findHits.length + ' match' + (findHits.length === 1 ? '' : 'es')) : 'No matches'; if(findHits.length){ findIndex = 0; markCurrent(); } } function markCurrent(){ findHits.forEach((h, i) => h.className = (i === findIndex ? 'find-hit-current' : 'find-hit')); if(findHits[findIndex]) findHits[findIndex].scrollIntoView({block:'center', behavior:'smooth'}); const cnt = document.getElementById('findCount'); if(cnt && findHits.length) cnt.textContent = (findIndex+1) + ' / ' + findHits.length; } function findNext(){ if(!findHits.length) return; findIndex = (findIndex+1) % findHits.length; markCurrent(); } function findPrev(){ if(!findHits.length) return; findIndex = (findIndex-1+findHits.length) % findHits.length; markCurrent(); } function replaceOne(){ const r = document.getElementById('replaceInput').value; if(findIndex < 0 || !findHits[findIndex]) return; const hit = findHits[findIndex]; const txt = document.createTextNode(r); hit.parentNode.replaceChild(txt, hit); findHits.splice(findIndex, 1); if(findIndex >= findHits.length) findIndex = 0; markCurrent(); markDirty(); } function replaceAll(){ const r = document.getElementById('replaceInput').value; if(!findHits.length) return; findHits.forEach(h => { h.parentNode.replaceChild(document.createTextNode(r), h); }); const n = findHits.length; findHits = []; findIndex = -1; const cnt = document.getElementById('findCount'); if(cnt) cnt.textContent = 'Replaced ' + n; markDirty(); } function openFind(){ document.getElementById('findbar').style.display = 'flex'; const i = document.getElementById('findInput'); i.focus(); i.select(); } function openReplace(){ openFind(); document.getElementById('replaceInput').focus(); } function closeFind(){ clearFindHits(); document.getElementById('findbar').style.display = 'none'; doc.focus(); } /* JUMP-TO TOC */ function buildJumpTo(){ const sel = document.getElementById('jumpTo'); if(!sel) return; sel.innerHTML = ''; const heads = doc.querySelectorAll('h1, h2, h3'); let i = 0; heads.forEach(h => { if(!h.id) h.id = 'sec-' + (i++); const indent = h.tagName === 'H1' ? '' : (h.tagName === 'H2' ? '— ' : ' · '); const o = document.createElement('option'); o.value = h.id; o.textContent = indent + (h.textContent || '').trim().slice(0, 60); sel.appendChild(o); }); } buildJumpTo(); let tocTimer = null; doc.addEventListener('input', () => { clearTimeout(tocTimer); tocTimer = setTimeout(buildJumpTo, 1500); }); /* TOOLBAR WIRING */ document.querySelectorAll('.tb button, .findbar button').forEach(btn => { btn.addEventListener('mousedown', e => e.preventDefault()); }); let savedRange = null; function saveSelection(){ try{ const sel = window.getSelection(); if(sel && sel.rangeCount){ const r = sel.getRangeAt(0); if(doc.contains(r.commonAncestorContainer)) savedRange = r.cloneRange(); } }catch(e){} } function restoreSelection(){ if(!savedRange) return; try{ const sel = window.getSelection(); sel.removeAllRanges(); sel.addRange(savedRange); }catch(e){} } doc.addEventListener('mouseup', saveSelection); doc.addEventListener('keyup', saveSelection); document.querySelectorAll('.tb select, .tb input[type=color]').forEach(el => { el.addEventListener('mousedown', saveSelection); el.addEventListener('focus', saveSelection); }); function wrapWithRestore(handler){ return function(e){ restoreSelection(); handler(e); }; } document.getElementById('styleSelect').addEventListener('change', wrapWithRestore(applyBlockStyle)); document.getElementById('lineSpacing').addEventListener('change', wrapWithRestore(applyLineSpacing)); document.getElementById('borderSelect').addEventListener('change', wrapWithRestore(applyBorder)); document.getElementById('listStyleSelect').addEventListener('change', wrapWithRestore(applyListStyle)); document.getElementById('jumpTo').addEventListener('change', e => { const id = e.target.value; if(!id) return; const target = document.getElementById(id); if(target){ target.scrollIntoView({behavior:'smooth', block:'start'}); } e.target.selectedIndex = 0; }); document.getElementById('findInput').addEventListener('input', e => highlightAll(e.target.value)); document.getElementById('findInput').addEventListener('keydown', e => { if(e.key === 'Enter'){ e.preventDefault(); e.shiftKey ? findPrev() : findNext(); } if(e.key === 'Escape'){ closeFind(); } }); document.getElementById('replaceInput').addEventListener('keydown', e => { if(e.key === 'Escape') closeFind(); }); /* HIGHLIGHT toggle */ function selectionHasHighlight(){ try{ const v = document.queryCommandValue('hiliteColor') || document.queryCommandValue('backColor'); if(!v) return false; const trimmed = ('' + v).trim(); if(!trimmed || trimmed === 'transparent' || /rgba?\(\s*0\s*,\s*0\s*,\s*0\s*,\s*0\s*\)/.test(trimmed)) return false; const m = trimmed.match(/rgba?\((\d+)\s*,\s*(\d+)\s*,\s*(\d+)/); if(m && +m[1] >= 250 && +m[2] >= 250 && +m[3] >= 250) return false; return true; }catch(e){ return false; } } function unhighlight(){ try{ document.execCommand('hiliteColor', false, 'transparent'); const sel = window.getSelection(); if(sel && sel.rangeCount){ const range = sel.getRangeAt(0); const it = document.createTreeWalker(doc, NodeFilter.SHOW_ELEMENT, { acceptNode: n => range.intersectsNode(n) ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP }); let n; while((n = it.nextNode())){ if(n.style && n.style.backgroundColor) n.style.backgroundColor = ''; } } doc.focus(); markDirty(); }catch(e){ console.warn('unhighlight failed', e); } } function toggleHighlight(){ if(selectionHasHighlight()){ unhighlight(); } else { const c = document.getElementById('bgColor').value; cmd('hiliteColor', c); } } /* CONFIGURABLE SHORTCUTS */ const ACTIONS = [ {id:'save', label:'Save now', def:'ctrl+s', run: () => saveNow()}, {id:'find', label:'Find', def:'ctrl+f', run: () => openFind()}, {id:'replace', label:'Find & Replace', def:'ctrl+h', run: () => openReplace()}, {id:'highlight', label:'Toggle highlight on selection', def:'ctrl+shift+h', run: () => toggleHighlight()}, {id:'unhighlight', label:'Remove highlight', def:'ctrl+shift+u', run: () => unhighlight()}, {id:'bold', label:'Bold', def:'ctrl+b', run: () => cmd('bold')}, {id:'italic', label:'Italic', def:'ctrl+i', run: () => cmd('italic')}, {id:'underline', label:'Underline', def:'ctrl+u', run: () => cmd('underline')}, {id:'strike', label:'Strikethrough', def:'', run: () => cmd('strikeThrough')}, {id:'super', label:'Superscript', def:'ctrl+shift+=', run: () => cmd('superscript')}, {id:'sub', label:'Subscript', def:'ctrl+=', run: () => cmd('subscript')}, {id:'selectAll', label:'Select all (in document)', def:'ctrl+a', run: () => { const range = document.createRange(); range.selectNodeContents(doc); const sel = window.getSelection(); sel.removeAllRanges(); sel.addRange(range); }}, {id:'indent', label:'Increase indent', def:'tab', run: () => { document.execCommand('indent'); markDirty(); }}, {id:'outdent', label:'Decrease indent', def:'shift+tab', run: () => { document.execCommand('outdent'); markDirty(); }}, {id:'undo', label:'Undo', def:'ctrl+z', run: () => cmd('undo')}, {id:'redo', label:'Redo', def:'ctrl+y', run: () => cmd('redo')} ]; let bindings = {}; function loadShortcuts(){ try{ const saved = JSON.parse(localStorage.getItem(SHORTCUT_KEY) || '{}'); bindings = {}; ACTIONS.forEach(a => { bindings[a.id] = saved[a.id] != null ? saved[a.id] : a.def; }); }catch(e){ bindings = Object.fromEntries(ACTIONS.map(a => [a.id, a.def])); } } function saveShortcuts(){ try{ localStorage.setItem(SHORTCUT_KEY, JSON.stringify(bindings)); }catch(e){ console.warn('save shortcuts failed', e); } } function resetShortcuts(){ if(!confirm('Reset all shortcuts to defaults?')) return; bindings = {}; ACTIONS.forEach(a => { bindings[a.id] = a.def; }); saveShortcuts(); renderShortcuts(); } function comboFromEvent(e){ if(e.key === 'Tab'){ return (e.shiftKey ? 'shift+' : '') + 'tab'; } if(e.key === 'Escape' || e.key === 'Control' || e.key === 'Shift' || e.key === 'Alt' || e.key === 'Meta') return null; const parts = []; if(e.ctrlKey || e.metaKey) parts.push('ctrl'); if(e.altKey) parts.push('alt'); if(e.shiftKey) parts.push('shift'); parts.push(e.key.toLowerCase()); return parts.join('+'); } loadShortcuts(); function openShortcuts(){ document.getElementById('shortcutsModal').classList.add('show'); renderShortcuts(); } function closeShortcuts(){ document.getElementById('shortcutsModal').classList.remove('show'); } function renderShortcuts(){ const tbl = document.getElementById('shortcutsTable'); tbl.innerHTML = 'ActionShortcut'; ACTIONS.forEach(a => { const tr = document.createElement('tr'); tr.innerHTML = ''+a.label+'' + '' + ''; tbl.appendChild(tr); }); tbl.querySelectorAll('.kb-btn').forEach(btn => { btn.onclick = () => { btn.textContent = '… press a key combo …'; btn.style.background = '#fff4e2'; const handler = (ev) => { ev.preventDefault(); const combo = comboFromEvent(ev); if(combo == null) return; const conflict = Object.entries(bindings).find(([k,v]) => v === combo && k !== btn.dataset.act); if(conflict){ const ok = confirm('That combo is already bound to "'+ACTIONS.find(a=>a.id===conflict[0]).label+'". Reassign anyway?'); if(!ok){ btn.textContent = bindings[btn.dataset.act] || '— click to set —'; btn.style.background='#fff'; window.removeEventListener('keydown', handler, true); return; } bindings[conflict[0]] = ''; } bindings[btn.dataset.act] = combo; saveShortcuts(); window.removeEventListener('keydown', handler, true); renderShortcuts(); }; window.addEventListener('keydown', handler, true); }; }); tbl.querySelectorAll('button[data-clear]').forEach(btn => { btn.onclick = () => { bindings[btn.dataset.clear] = ''; saveShortcuts(); renderShortcuts(); }; }); } document.addEventListener('keydown', e => { if(document.getElementById('shortcutsModal').classList.contains('show')) return; const combo = comboFromEvent(e); if(!combo) return; for(const a of ACTIONS){ if(bindings[a.id] && bindings[a.id] === combo){ if((a.id === 'indent' || a.id === 'outdent') && !doc.contains(document.activeElement)) return; if(a.id === 'selectAll' && !doc.contains(document.activeElement)) return; e.preventDefault(); try{ a.run(); }catch(err){ console.warn('shortcut '+a.id+' failed:', err); } return; } } }); /* PUBLIC */ window.cmd = cmd; window.changeCase = changeCase; window.applyShade = applyShade; window.unhighlight = unhighlight; window.toggleHighlight = toggleHighlight; window.openShortcuts = openShortcuts; window.closeShortcuts = closeShortcuts; window.resetShortcuts = resetShortcuts; window.insertHorizontalRule = insertHorizontalRule; window.insertPageBreak = insertPageBreak; window.insertImageFromFile = insertImageFromFile; window.openFind = openFind; window.openReplace = openReplace; window.closeFind = closeFind; window.findNext = findNext; window.findPrev = findPrev; window.replaceOne = replaceOne; window.replaceAll = replaceAll; window.resetDoc = resetDoc; window.downloadHTML = downloadHTML; })();